From 4a44e097a21c0e443731514085d2f51c86153970 Mon Sep 17 00:00:00 2001 From: deng-cc <360075602@qq.com> Date: Mon, 30 Sep 2019 11:16:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dmybatis=E5=88=AB=E5=90=8D?= =?UTF-8?q?=E7=B1=BB=E6=89=AB=E6=8F=8F=E6=97=A0=E6=B3=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=9A=E7=9B=AE=E5=BD=95=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/framework/config/MyBatisConfig.java | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java index ccd32f468..80131249f 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import javax.sql.DataSource; + import org.apache.ibatis.io.VFS; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; @@ -38,36 +39,43 @@ public class MyBatisConfig { ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); - typeAliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/" + DEFAULT_RESOURCE_PATTERN; + List allResult = new ArrayList(); try { - List result = new ArrayList(); - Resource[] resources = resolver.getResources(typeAliasesPackage); - if (resources != null && resources.length > 0) + for (String aliasesPackage : typeAliasesPackage.split(",")) { - MetadataReader metadataReader = null; - for (Resource resource : resources) + List result = new ArrayList(); + aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + + ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN; + Resource[] resources = resolver.getResources(aliasesPackage); + if (resources != null && resources.length > 0) { - if (resource.isReadable()) + MetadataReader metadataReader = null; + for (Resource resource : resources) { - metadataReader = metadataReaderFactory.getMetadataReader(resource); - try - { - result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); - } - catch (ClassNotFoundException e) + if (resource.isReadable()) { - e.printStackTrace(); + metadataReader = metadataReaderFactory.getMetadataReader(resource); + try + { + result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); + } + catch (ClassNotFoundException e) + { + e.printStackTrace(); + } } } } + if (result.size() > 0) + { + HashSet hashResult = new HashSet(result); + allResult.addAll(hashResult); + } } - if (result.size() > 0) + if (allResult.size() > 0) { - HashSet h = new HashSet(result); - result.clear(); - result.addAll(h); - typeAliasesPackage = String.join(",", (String[]) result.toArray(new String[0])); + typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0])); } else {