diff --git a/jcommon/docean-plugin/docean-plugin-mybatis/pom.xml b/jcommon/docean-plugin/docean-plugin-mybatis/pom.xml index c1a775cf4..c361e0e97 100644 --- a/jcommon/docean-plugin/docean-plugin-mybatis/pom.xml +++ b/jcommon/docean-plugin/docean-plugin-mybatis/pom.xml @@ -25,7 +25,7 @@ 4.0.0 docean-plugin-mybatis - 1.4.7-SNAPSHOT + 1.5.0-SNAPSHOT diff --git a/jcommon/docean-plugin/docean-plugin-mybatis/src/main/java/com/xiaomi/youpin/docean/plugin/mybatis/MybatisPlugin.java b/jcommon/docean-plugin/docean-plugin-mybatis/src/main/java/com/xiaomi/youpin/docean/plugin/mybatis/MybatisPlugin.java index 25e03d5bb..ed1a2b14d 100644 --- a/jcommon/docean-plugin/docean-plugin-mybatis/src/main/java/com/xiaomi/youpin/docean/plugin/mybatis/MybatisPlugin.java +++ b/jcommon/docean-plugin/docean-plugin-mybatis/src/main/java/com/xiaomi/youpin/docean/plugin/mybatis/MybatisPlugin.java @@ -66,6 +66,10 @@ public class MybatisPlugin implements IPlugin { private boolean serverLess = false; + private static SqlSessionFactory sqlSessionFactory; + + private static String mapperName = "_mapperName_"; + @SneakyThrows @Override @@ -118,6 +122,7 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one Thread.currentThread().setContextClassLoader(ioc.getClassLoader()); } SqlSessionFactory factory = bean.buildSqlSessionFactory(); + MybatisPlugin.sqlSessionFactory = factory; ioc.putBean("mybatis_" + beanName + config.getName(), factory); if (System.getenv("mybatis_mapper_annotation") != null) { factory.getConfiguration().addMappers(System.getenv("mybatis_mapper_annotation")); @@ -134,10 +139,12 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one new SqlSessionInterceptor(factory))); if (one) { ioc.putBean(it.getName(), proxy); + ioc.putBean(mapperName + it.getName(), it.getName()); } else { String name = it.getSimpleName() + ":" + config.getName(); log.info("mybatis dao name:{} add", name); ioc.putBean(name, proxy); + ioc.putBean(mapperName + name, it.getName()); } }); } finally { @@ -149,6 +156,14 @@ private void addDAO(Ioc ioc, String beanName, String mapperLocation, boolean one } } + public static SqlSessionFactory getSqlSessionFactory() { + return sqlSessionFactory; + } + + public static String getMapperName() { + return mapperName; + } + @Override public String version() { return "0.0.1:2022-03-29:goodjava@qq.com";