flushStatements() {
* }
*
*
- * The implementation of {@link BeanClosure} forces bean context to use {@link BeanClosure#destroy()} method
+ * The implementation of {@link BeanClosure} forces bean context to use {@link BeanClosure#destruct(ApplicationContext)} ()} method
* instead of {@link SqlSessionTemplate#close()} to shutdown gently.
*
* @see SqlSessionTemplate#close()
@@ -365,7 +366,7 @@ public List flushStatements() {
* @see "org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME"
*/
@Override
- public void destroy() {
+ public void destruct(ApplicationContext applicationContext) {
// This method forces spring disposer to avoid call of SqlSessionTemplate.close() which gives
// UnsupportedOperationException
}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MappedBeanRegister.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MappedBeanRegister.java
index 6f3fce7..f083eaa 100644
--- a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MappedBeanRegister.java
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MappedBeanRegister.java
@@ -9,53 +9,48 @@
*/
package com.truthbean.debbie.mybatis.annotation;
-import com.truthbean.debbie.bean.BeanInitialization;
-import com.truthbean.debbie.bean.DebbieBeanInfo;
-import com.truthbean.debbie.bean.DebbieClassBeanInfo;
+import com.truthbean.debbie.bean.BeanFactory;
+import com.truthbean.debbie.bean.BeanInfoManager;
+import com.truthbean.debbie.bean.BeanRegister;
+import com.truthbean.debbie.bean.ClassBeanInfo;
import com.truthbean.debbie.core.ApplicationContext;
-import com.truthbean.debbie.jdbc.datasource.DataSourceFactoryBeanRegister;
import com.truthbean.debbie.mybatis.DebbieMapperFactory;
+import com.truthbean.debbie.mybatis.SqlSessionFactoryBeanFactory;
import com.truthbean.debbie.mybatis.SqlSessionFactoryHandler;
-import com.truthbean.debbie.properties.DebbieConfigurationCenter;
+import com.truthbean.debbie.mybatis.configuration.MybatisConfiguration;
+import com.truthbean.debbie.mybatis.transaction.MybatisTransactionFactory;
import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.session.SqlSessionFactory;
-
-import java.util.Set;
/**
* @author TruthBean
* @since 0.0.2
* Created on 2019/06/02 18:27.
*/
-public class MappedBeanRegister extends DataSourceFactoryBeanRegister {
+public class MappedBeanRegister implements BeanRegister {
private final SqlSessionFactoryHandler sqlSessionFactoryHandler;
- private final BeanInitialization beanInitialization;
- private final ApplicationContext context;
- public MappedBeanRegister(DebbieConfigurationCenter configurationFactory, ApplicationContext context) {
- super(configurationFactory, context);
- this.context = context;
- sqlSessionFactoryHandler = new SqlSessionFactoryHandler(configurationFactory, context);
- beanInitialization = context.getBeanInitialization();
+ public MappedBeanRegister(ApplicationContext context, MybatisConfiguration mybatisConfiguration) {
+ sqlSessionFactoryHandler = new SqlSessionFactoryHandler(context, mybatisConfiguration);
+ BeanInfoManager beanInfoManager = context.getBeanInfoManager();
+ beanInfoManager.register(new SqlSessionFactoryBeanFactory(sqlSessionFactoryHandler));
+ sqlSessionFactoryHandler.registerMybatisConfiguration(context.getBeanInfoManager());
+ }
+
+ @Override
+ public boolean support(ClassBeanInfo beanInfo) {
+ Class> beanClass = beanInfo.getBeanClass();
+ return beanClass.isInterface() && support(beanInfo, Mapper.class);
}
- @SuppressWarnings({"unchecked", "rawtypes"})
- public void registerMapper() {
- Set> annotatedClass = beanInitialization.getAnnotatedClass(Mapper.class);
- if (annotatedClass != null && !annotatedClass.isEmpty()) {
- for (DebbieClassBeanInfo> mapperBean : annotatedClass) {
- DebbieMapperFactory mapperFactory = new DebbieMapperFactory<>(mapperBean.getBeanClass(),
- sqlSessionFactoryHandler);
- mapperFactory.setGlobalBeanFactory(context.getGlobalBeanFactory());
- mapperBean.setBeanFactory(mapperFactory);
- beanInitialization.refreshBean(mapperBean);
- context.refreshBeans();
- }
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public BeanFactory getBeanFactory(ClassBeanInfo beanInfo) {
+ return new DebbieMapperFactory<>((Class) beanInfo.getBeanClass(), sqlSessionFactoryHandler);
}
- public void registerSqlSessionFactory() {
- registerSingletonBean(sqlSessionFactoryHandler.buildSqlSessionFactory(), SqlSessionFactory.class, "sqlSessionFactory");
+ @Override
+ public int getOrder() {
+ return 11;
}
}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MybatisBeanRegister.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MybatisBeanRegister.java
new file mode 100644
index 0000000..5a1d6af
--- /dev/null
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/annotation/MybatisBeanRegister.java
@@ -0,0 +1,40 @@
+package com.truthbean.debbie.mybatis.annotation;
+
+import com.truthbean.debbie.bean.*;
+import com.truthbean.debbie.core.ApplicationContext;
+import org.apache.ibatis.type.Alias;
+import org.apache.ibatis.type.MappedJdbcTypes;
+import org.apache.ibatis.type.MappedTypes;
+
+/**
+ * @author TruthBean
+ * @since 0.5.3
+ * Created on 2021/12/18 20:35.
+ */
+public class MybatisBeanRegister implements BeanRegister {
+
+ private final BeanInfoManager beanInfoManager;
+
+ public MybatisBeanRegister(ApplicationContext context) {
+ beanInfoManager = context.getBeanInfoManager();
+ }
+
+ @Override
+ public boolean support(ClassBeanInfo beanInfo) {
+ Class> beanClass = beanInfo.getBeanClass();
+ return beanClass.isInterface()
+ && (support(beanInfo, Alias.class) || support(beanInfo, MappedTypes.class) || support(beanInfo, MappedJdbcTypes.class))
+ && !beanInfoManager.isBeanRegistered(beanClass);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public BeanFactory getBeanFactory(ClassBeanInfo beanInfo) {
+ return new DebbieReflectionBeanFactory<>((Class) beanInfo.getBeanClass());
+ }
+
+ @Override
+ public int getOrder() {
+ return 11;
+ }
+}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisConfiguration.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisConfiguration.java
index 2971557..985437f 100644
--- a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisConfiguration.java
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisConfiguration.java
@@ -46,6 +46,11 @@ public class MybatisConfiguration implements DebbieConfiguration {
private DatabaseIdProvider databaseIdProvider;
private Cache cache;
+ @Override
+ public boolean isEnable() {
+ return true;
+ }
+
@Override
public String getName() {
return name;
@@ -152,7 +157,7 @@ public void setCache(Cache cache) {
}
@Override
- public void reset() {
+ public void close() {
}
}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisProperties.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisProperties.java
index 77bf186..461f6ca 100644
--- a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisProperties.java
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/configuration/MybatisProperties.java
@@ -12,15 +12,15 @@
import com.truthbean.debbie.core.ApplicationContext;
import com.truthbean.debbie.env.EnvironmentContentHolder;
import com.truthbean.debbie.io.ResourceResolver;
+import com.truthbean.debbie.properties.DebbieProperties;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
/**
* @author truthbean
* @since 0.0.2
*/
-public class MybatisProperties extends EnvironmentContentHolder {
+public class MybatisProperties extends EnvironmentContentHolder implements DebbieProperties {
public static final String ENABLE_KEY = "debbie.mybatis.enable";
//===========================================================================
@@ -30,6 +30,7 @@ public class MybatisProperties extends EnvironmentContentHolder {
private static final String MYBATIS_MAPPER_LOCATIONS = "debbie.mybatis.mapper-locations";
//===========================================================================
+ private final Map map = new HashMap<>();
private final MybatisConfiguration configuration;
private static MybatisProperties instance;
@@ -47,6 +48,7 @@ public MybatisProperties(ApplicationContext context) {
List list = getStringListValue(MYBATIS_MAPPER_LOCATIONS, ";");
ResourceResolver resourceResolver = context.getResourceResolver();
resolveMapperLocations(list, resourceResolver);
+ map.put(DEFAULT_PROFILE, configuration);
}
private void resolveMapperLocations(List patternList, ResourceResolver resourceResolver) {
@@ -69,4 +71,20 @@ public static MybatisConfiguration toConfiguration(ApplicationContext context) {
public MybatisConfiguration loadConfiguration() {
return configuration;
}
+
+ @Override
+ public Set getProfiles() {
+ return map.keySet();
+ }
+
+ @Override
+ public MybatisConfiguration getConfiguration(String name, ApplicationContext applicationContext) {
+ return map.get(name);
+ }
+
+ @Override
+ public void close() throws Exception {
+ map.clear();
+ instance = null;
+ }
}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionFactory.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionFactory.java
new file mode 100644
index 0000000..a78ed8a
--- /dev/null
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionFactory.java
@@ -0,0 +1,25 @@
+package com.truthbean.debbie.mybatis.transaction;
+
+/**
+ * @author TruthBean
+ * @since 0.5.3
+ * Created on 2021/12/26 18:15.
+ */
+public enum MybatisTransactionFactory {
+ /**
+ * org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory
+ */
+ JDBC,
+ /**
+ * org.apache.ibatis.transaction.managed.ManagedTransactionFactory
+ */
+ MANAGED,
+ /**
+ * spring-mybatis
+ */
+ SPRING,
+ /**
+ * com.truthbean.debbie.mybatis.transaction.DebbieManagedTransactionFactory
+ */
+ DEBBIE
+}
diff --git a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionalHandler.java b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionalHandler.java
index 9f5b6e9..fd0f3d0 100644
--- a/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionalHandler.java
+++ b/boot/mybatis/src/main/java/com/truthbean/debbie/mybatis/transaction/MybatisTransactionalHandler.java
@@ -9,7 +9,6 @@
*/
package com.truthbean.debbie.mybatis.transaction;
-import com.truthbean.debbie.bean.BeanInitialization;
import com.truthbean.debbie.core.ApplicationContext;
import com.truthbean.debbie.jdbc.transaction.TransactionInfo;
import com.truthbean.debbie.proxy.MethodProxyHandler;
@@ -35,7 +34,7 @@ public class MybatisTransactionalHandler implements MethodProxyHandler", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "com.truthbean.debbie.mybatis.configuration.MyBatisConfigurationSettings",
+ "methods": [
+ { "name": "", "parameterTypes": [] },
+ { "name": "setCacheEnabled", "parameterTypes": ["boolean"] },
+ { "name": "setLazyLoadingEnabled", "parameterTypes": ["boolean"] },
+ { "name": "setAggressiveLazyLoading", "parameterTypes": ["boolean"] },
+ { "name": "setMultipleResultSetsEnabled", "parameterTypes": ["boolean"] },
+ { "name": "setUseColumnLabel", "parameterTypes": ["boolean"] },
+ { "name": "setUseGeneratedKeys", "parameterTypes": ["boolean"] },
+ { "name": "setAutoMappingBehavior", "parameterTypes": ["org.apache.ibatis.session.AutoMappingBehavior"] },
+ { "name": "setAutoMappingUnknownColumnBehavior", "parameterTypes": ["org.apache.ibatis.session.AutoMappingUnknownColumnBehavior"] },
+ { "name": "setDefaultExecutorType", "parameterTypes": ["org.apache.ibatis.session.ExecutorType"] },
+ { "name": "setDefaultStatementTimeout", "parameterTypes": ["java.lang.Integer"] },
+ { "name": "setDefaultFetchSize", "parameterTypes": ["java.lang.Integer"] },
+ { "name": "setSafeRowBoundsEnabled", "parameterTypes": ["boolean"] },
+ { "name": "setSafeResultHandlerEnabled", "parameterTypes": ["boolean"] },
+ { "name": "setMapUnderscoreToCamelCase", "parameterTypes": ["boolean"] },
+ { "name": "setLocalCacheScope", "parameterTypes": ["org.apache.ibatis.session.LocalCacheScope"] },
+ { "name": "setJdbcTypeForNull", "parameterTypes": ["org.apache.ibatis.type.JdbcType"] },
+ { "name": "setJdbcTypeForNull", "parameterTypes": ["org.apache.ibatis.type.JdbcType"] },
+ { "name": "setLazyLoadTriggerMethods", "parameterTypes": ["java.util.Set"] },
+ { "name": "setDefaultScriptingLanguage", "parameterTypes": ["java.lang.Class"] },
+ { "name": "setDefaultEnumTypeHandler", "parameterTypes": ["java.lang.Class"] },
+ { "name": "setCallSettersOnNulls", "parameterTypes": ["boolean"] },
+ { "name": "setReturnInstanceForEmptyRow", "parameterTypes": ["boolean"] },
+ { "name": "setLogPrefix", "parameterTypes": ["java.lang.String"] },
+ { "name": "setLogImpl", "parameterTypes": ["java.lang.Class"] },
+ { "name": "setProxyFactory", "parameterTypes": ["org.apache.ibatis.executor.loader.ProxyFactory"] },
+ { "name": "setVfsImpl", "parameterTypes": ["java.lang.Class"] },
+ { "name": "setUseActualParamName", "parameterTypes": ["boolean"] },
+ { "name": "setConfigurationFactory", "parameterTypes": ["java.lang.Class"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "javassist.util.proxy.ProxyFactory",
+ "methods": [
+ { "name": "", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.javassist.util.proxy.ProxyFactory",
+ "methods": [
+ { "name": "", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.slf4j.Slf4jImpl",
+ "allDeclaredFields": true,
+ "allDeclaredConstructors": true,
+ "allDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true
+ },
+ {
+ "name": "org.slf4j.Marker",
+ "allDeclaredFields": true,
+ "allDeclaredConstructors": true,
+ "allDeclaredMethods": true,
+ "allPublicMethods": true,
+ "allDeclaredClasses": true
+ },
+ {
+ "name": "org.apache.ibatis.logging.nologging.NoLoggingImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.stdout.StdOutImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.log4j2.Log4j2Impl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.log4j.Log4jImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.logging.slf4j.Slf4jImpl",
+ "methods": [
+ { "name": "", "parameterTypes": ["java.lang.String"] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.io.JBoss6VFS",
+ "allPublicConstructors": true
+ },
+ {
+ "name": "org.apache.ibatis.io.DefaultVFS",
+ "allPublicConstructors": true
+ },
+ {
+ "name": "org.apache.ibatis.type.JdbcType",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "java.lang.invoke.MethodHandles",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.scripting.xmltags.XMLLanguageDriver",
+ "methods": [
+ { "name": "", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name": "org.apache.ibatis.scripting.defaults.RawLanguageDriver",
+ "methods": [
+ { "name": "", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ }
+]
\ No newline at end of file
diff --git a/boot/mybatis/src/main/resources/META-INF/native-image/com.truthbean.debbie/mybatis/resource-config.json b/boot/mybatis/src/main/resources/META-INF/native-image/com.truthbean.debbie/mybatis/resource-config.json
new file mode 100644
index 0000000..caa30d8
--- /dev/null
+++ b/boot/mybatis/src/main/resources/META-INF/native-image/com.truthbean.debbie/mybatis/resource-config.json
@@ -0,0 +1,13 @@
+{
+ "resources": [
+ {
+ "pattern": ".*/*.*xml$"
+ },
+ {
+ "pattern": ".*/*.*dtd$"
+ },
+ {
+ "pattern": ".*/*.*xsd$"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/boot/mybatis/src/test/java/com/truthbean/debbie/check/mybatis/MybatisTest.java b/boot/mybatis/src/test/java/com/truthbean/debbie/check/mybatis/MybatisTest.java
index d5b9c93..8632f11 100644
--- a/boot/mybatis/src/test/java/com/truthbean/debbie/check/mybatis/MybatisTest.java
+++ b/boot/mybatis/src/test/java/com/truthbean/debbie/check/mybatis/MybatisTest.java
@@ -13,7 +13,8 @@
import com.truthbean.debbie.core.ApplicationFactory;
import com.truthbean.debbie.jdbc.datasource.DataSourceFactory;
import com.truthbean.debbie.mybatis.SqlSessionFactoryHandler;
-import com.truthbean.debbie.properties.DebbieConfigurationCenter;
+import com.truthbean.debbie.mybatis.configuration.MybatisConfiguration;
+import com.truthbean.debbie.mybatis.configuration.MybatisProperties;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.jupiter.api.BeforeAll;
@@ -25,19 +26,17 @@
public class MybatisTest {
private static ApplicationContext applicationContext;
- private static DebbieConfigurationCenter configurationFactory;
@BeforeAll
static void before() {
ApplicationFactory applicationFactory = ApplicationFactory.configure(MybatisTest.class);
applicationContext = applicationFactory.getApplicationContext();
DataSourceFactory dataSourceFactory = applicationContext.getGlobalBeanFactory().factory("dataSourceFactory");
- configurationFactory = applicationContext.getConfigurationCenter();
}
@Test
public void testSqlSessionFactory() throws IOException {
- SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(configurationFactory, applicationContext);
+ SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(applicationContext, new MybatisProperties(applicationContext).loadConfiguration());
SqlSessionFactory sqlSessionFactory = handler.buildSqlSessionFactory();
System.out.println(sqlSessionFactory);
@@ -45,7 +44,7 @@ public void testSqlSessionFactory() throws IOException {
@Test
public void testSelectOneSurname() throws IOException {
- SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(configurationFactory, applicationContext);
+ SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(applicationContext, new MybatisProperties(applicationContext).loadConfiguration());
SqlSessionFactory sqlSessionFactory = handler.buildSqlSessionFactory();
try (SqlSession session = sqlSessionFactory.openSession()) {
@@ -57,7 +56,7 @@ public void testSelectOneSurname() throws IOException {
@Test
public void testDataTimeMapper() throws IOException {
- SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(configurationFactory, applicationContext);
+ SqlSessionFactoryHandler handler = new SqlSessionFactoryHandler(applicationContext, new MybatisProperties(applicationContext).loadConfiguration());
SqlSessionFactory sqlSessionFactory = handler.buildSqlSessionFactory();
try (SqlSession session = sqlSessionFactory.openSession()) {
diff --git a/boot/pom.xml b/boot/pom.xml
index 9cb068f..8e42258 100644
--- a/boot/pom.xml
+++ b/boot/pom.xml
@@ -32,9 +32,9 @@
- 11
- 11
- 11
+ 17
+ 17
+ 17
diff --git a/boot/servlet/pom.xml b/boot/servlet/pom.xml
index 0a8e17d..cb0a28b 100644
--- a/boot/servlet/pom.xml
+++ b/boot/servlet/pom.xml
@@ -12,9 +12,9 @@
debbie-servlet
- 11
- 11
- 11
+ 17
+ 17
+ 17
diff --git a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletApplicationInitializer.java b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletApplicationInitializer.java
index b2794de..aa83245 100644
--- a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletApplicationInitializer.java
+++ b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletApplicationInitializer.java
@@ -52,8 +52,9 @@ public void onStartup(Set> classes, ServletContext ctx) throws ServletE
handler.registerFilter(ctx);
// if run with war package
- if (debbieApplication == null)
- super.postCallStarter();
+ if (debbieApplication == null) {
+ super.postCallStarter(this.factory());
+ }
}
private static final Logger LOGGER = LoggerFactory.getLogger(ServletApplicationInitializer.class);
diff --git a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletContextHandler.java b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletContextHandler.java
index 3be7c55..ac97a01 100644
--- a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletContextHandler.java
+++ b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletContextHandler.java
@@ -9,7 +9,7 @@
*/
package com.truthbean.debbie.servlet;
-import com.truthbean.debbie.bean.BeanInitialization;
+import com.truthbean.debbie.bean.BeanInfoManager;
import com.truthbean.debbie.core.ApplicationContext;
import com.truthbean.debbie.mvc.csrf.CsrfFilter;
import com.truthbean.debbie.mvc.filter.*;
@@ -30,14 +30,14 @@
public class ServletContextHandler {
private final ApplicationContext applicationContext;
- private final BeanInitialization beanInitialization;
+ private final BeanInfoManager beanInitialization;
private final ClassLoader classLoader;
public ServletContextHandler(ServletContext servletContext, ApplicationContext handler) {
setServletConfiguration();
- beanInitialization = handler.getBeanInitialization();
+ beanInitialization = handler.getBeanInfoManager();
this.applicationContext = handler;
this.classLoader = this.applicationContext.getClassLoader();
diff --git a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletModuleStarter.java b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletModuleStarter.java
index 2f16df5..a621065 100644
--- a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletModuleStarter.java
+++ b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletModuleStarter.java
@@ -9,9 +9,10 @@
*/
package com.truthbean.debbie.servlet;
+import com.truthbean.debbie.bean.BeanInfoManager;
import com.truthbean.debbie.boot.DebbieModuleStarter;
import com.truthbean.debbie.core.ApplicationContext;
-import com.truthbean.debbie.properties.DebbieConfigurationCenter;
+import com.truthbean.debbie.properties.PropertiesConfigurationBeanFactory;
/**
* @author truthbean
@@ -20,8 +21,9 @@
public class ServletModuleStarter implements DebbieModuleStarter {
@Override
- public void configure(DebbieConfigurationCenter configurationFactory, ApplicationContext applicationContext) {
- configurationFactory.register(new ServletProperties(), ServletConfiguration.class);
+ public void registerBean(ApplicationContext applicationContext, BeanInfoManager beanInfoManager) {
+ var beanFactory = new PropertiesConfigurationBeanFactory<>(new ServletProperties(), ServletConfiguration.class);
+ beanInfoManager.register(beanFactory);
}
@Override
diff --git a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletProperties.java b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletProperties.java
index 4928422..d15eb37 100644
--- a/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletProperties.java
+++ b/boot/servlet/src/main/java/com/truthbean/debbie/servlet/ServletProperties.java
@@ -9,6 +9,7 @@
*/
package com.truthbean.debbie.servlet;
+import com.truthbean.common.mini.util.StringUtils;
import com.truthbean.debbie.bean.BeanScanConfiguration;
import com.truthbean.debbie.core.ApplicationContext;
import com.truthbean.debbie.env.EnvironmentContentHolder;
@@ -17,6 +18,10 @@
import com.truthbean.debbie.properties.ClassesScanProperties;
import com.truthbean.debbie.properties.DebbieProperties;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author TruthBean
* @since 0.0.1
@@ -28,6 +33,7 @@ public class ServletProperties extends EnvironmentContentHolder implements Debbi
//========================================================================================
+ private final Map map = new HashMap<>();
private static ServletConfiguration configuration;
public static ServletConfiguration toConfiguration(ClassLoader classLoader) {
if (configuration != null) {
@@ -46,8 +52,27 @@ public static ServletConfiguration toConfiguration(ClassLoader classLoader) {
}
@Override
- public ServletConfiguration toConfiguration(ApplicationContext applicationContext) {
+ public Set getProfiles() {
+ return map.keySet();
+ }
+
+ @Override
+ public ServletConfiguration getConfiguration(String name, ApplicationContext applicationContext) {
+ if (DEFAULT_PROFILE.equals(name) || !StringUtils.hasText(name)) {
+ return getConfiguration(applicationContext);
+ }
+ return map.get(name);
+ }
+
+ @Override
+ public ServletConfiguration getConfiguration(ApplicationContext applicationContext) {
ClassLoader classLoader = applicationContext.getClassLoader();
return toConfiguration(classLoader);
}
+
+ @Override
+ public void close() throws Exception {
+ map.clear();
+ configuration = null;
+ }
}
diff --git a/boot/servlet/src/main/resources/META-INF/native-image/com.truthbean.debbie/debbie-servlet/reflect-config.json b/boot/servlet/src/main/resources/META-INF/native-image/com.truthbean.debbie/debbie-servlet/reflect-config.json
index cc49654..e1df887 100644
--- a/boot/servlet/src/main/resources/META-INF/native-image/com.truthbean.debbie/debbie-servlet/reflect-config.json
+++ b/boot/servlet/src/main/resources/META-INF/native-image/com.truthbean.debbie/debbie-servlet/reflect-config.json
@@ -46,5 +46,17 @@
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
+ },
+ {
+ "name": "org.apache.tomcat.util.modeler.modules.MbeansDescriptorsIntrospectionSource",
+ "methods": [
+ { "name": "", "parameterTypes": [] }
+ ],
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
}
]
\ No newline at end of file
diff --git a/boot/spring/pom.xml b/boot/spring/pom.xml
index b970a78..17baca7 100644
--- a/boot/spring/pom.xml
+++ b/boot/spring/pom.xml
@@ -12,9 +12,9 @@
debbie-spring
- 11
- 11
- 11
+ 17
+ 17
+ 17
diff --git a/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieBeanRegistrar.java b/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieBeanRegistrar.java
index 6d29c4a..234b134 100644
--- a/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieBeanRegistrar.java
+++ b/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieBeanRegistrar.java
@@ -10,10 +10,10 @@
package com.truthbean.debbie.spring;
import com.truthbean.Logger;
+import com.truthbean.debbie.bean.BeanFactory;
import com.truthbean.debbie.bean.BeanInfo;
-import com.truthbean.debbie.bean.BeanInfoFactory;
+import com.truthbean.debbie.bean.BeanInfoManager;
import com.truthbean.debbie.bean.BeanScanConfiguration;
-import com.truthbean.debbie.boot.DebbieApplication;
import com.truthbean.debbie.core.ApplicationContext;
import com.truthbean.debbie.core.ApplicationFactory;
import com.truthbean.LoggerFactory;
@@ -55,7 +55,7 @@ public DebbieBeanRegistrar() {
@Override
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(BEAN_INJECT_ANNOTATION_PROCESSOR_BEAN_NAME)) {
- RootBeanDefinition definition = new RootBeanDefinition(DebbieBeanInjectAnnotationBeanPostProcessor.class);
+ RootBeanDefinition definition = new RootBeanDefinition(DebbieBeanInjectAnnotationBeanPostProcessor.class, DebbieBeanInjectAnnotationBeanPostProcessor::new);
definition.setSource(null);
definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN_INJECT_ANNOTATION_PROCESSOR_BEAN_NAME, definition);
@@ -78,15 +78,15 @@ public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMe
configuration.addScanExcludeClasses(excludeClasses);
configuration.addScanExcludePackages(excludePackages);
- applicationFactory.config(configuration);
+ applicationFactory.config(configuration).create().build();
ApplicationContext applicationContext = applicationFactory.getApplicationContext();
- BeanInfoFactory debbieBeanInfoFactory = applicationContext.getBeanInfoFactory();
- Set> allDebbieBeanInfo = debbieBeanInfoFactory.getAllDebbieBeanInfo();
+ BeanInfoManager debbieBeanInfoFactory = applicationContext.getBeanInfoManager();
+ Set allDebbieBeanInfo = debbieBeanInfoFactory.getAllBeanInfo();
for (BeanInfo> beanInfo : allDebbieBeanInfo) {
Class beanClass = beanInfo.getBeanClass();
- SpringDebbieBeanFactory factory = new SpringDebbieBeanFactory<>(debbieBeanInfoFactory, beanInfo);
- factory.setGlobalBeanFactory(applicationContext.getGlobalBeanFactory());
- registry.registerBeanDefinition(beanInfo.getServiceName(), new RootBeanDefinition(beanClass, () -> factory));
+ if (beanInfo instanceof BeanFactory> beanFactory) {
+ registry.registerBeanDefinition(beanInfo.getServiceName(), new RootBeanDefinition(beanClass, () -> beanFactory.factoryBean(applicationContext)));
+ }
}
}
}
diff --git a/boot/spring/src/main/java/com/truthbean/debbie/spring/SpringDebbieBeanFactory.java b/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieSpringBeanFactory.java
similarity index 57%
rename from boot/spring/src/main/java/com/truthbean/debbie/spring/SpringDebbieBeanFactory.java
rename to boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieSpringBeanFactory.java
index c8740c3..92b073e 100644
--- a/boot/spring/src/main/java/com/truthbean/debbie/spring/SpringDebbieBeanFactory.java
+++ b/boot/spring/src/main/java/com/truthbean/debbie/spring/DebbieSpringBeanFactory.java
@@ -11,11 +11,8 @@
import com.truthbean.Logger;
import com.truthbean.LoggerFactory;
-import com.truthbean.debbie.bean.BeanCreatedException;
-import com.truthbean.debbie.bean.BeanFactory;
-import com.truthbean.debbie.bean.BeanInfo;
-import com.truthbean.debbie.bean.BeanInfoFactory;
-import com.truthbean.debbie.bean.GlobalBeanFactory;
+import com.truthbean.debbie.bean.*;
+import com.truthbean.debbie.core.ApplicationContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
@@ -27,24 +24,24 @@
* @since 0.0.2
* Created on 2020-06-03 23:12
*/
-public class SpringDebbieBeanFactory implements BeanFactory,
+public abstract class DebbieSpringBeanFactory implements BeanFactory,
// spring
FactoryBean, BeanFactoryAware, BeanNameAware {
- private GlobalBeanFactory globalBeanFactory;
+ private ApplicationContext applicationContext;
private volatile Class beanClass;
private volatile String name;
- private boolean singleton = false;
+ private final boolean singleton = false;
private org.springframework.beans.factory.BeanFactory springBeanFactory;
private volatile Logger logger;
- private volatile BeanInfoFactory debbieBeanInfoFactory;
+ private volatile BeanInfoManager debbieBeanInfoFactory;
private final boolean isCreateBySpring;
- public SpringDebbieBeanFactory() {
+ public DebbieSpringBeanFactory() {
this.isCreateBySpring = true;
}
@@ -53,35 +50,32 @@ public void setBeanName(@NonNull String name) {
this.name = name;
}
- public void setBeanClass(Class beanClass) {
- this.beanClass = beanClass;
- }
-
- public SpringDebbieBeanFactory(BeanInfoFactory debbieBeanInfoFactory, Class beanClass, String name) {
- this.debbieBeanInfoFactory = debbieBeanInfoFactory;
- this.beanClass = beanClass;
- this.name = name;
- this.logger = LoggerFactory.getLogger("com.truthbean.debbie.spring.SpringDebbieBeanFactory<" + beanClass.getName() + ">");
- this.isCreateBySpring = false;
- }
-
- public SpringDebbieBeanFactory(BeanInfoFactory debbieBeanInfoFactory, BeanInfo beanInfo) {
- this.debbieBeanInfoFactory = debbieBeanInfoFactory;
- this.beanClass = beanInfo.getBeanClass();
+ public DebbieSpringBeanFactory(ApplicationContext applicationContext, BeanInfo beanInfo) {
+ this.applicationContext = applicationContext;
+ this.debbieBeanInfoFactory = applicationContext.getBeanInfoManager();
+ this.beanClass = (Class) beanInfo.getBeanClass();
this.name = beanInfo.getServiceName();
- this.logger = LoggerFactory.getLogger("com.truthbean.debbie.spring.SpringDebbieBeanFactory<" + beanClass.getName() + ">");
+ this.logger = LoggerFactory.getLogger("com.truthbean.debbie.spring.DebbieSpringBeanFactory<" + beanClass.getName() + ">");
this.isCreateBySpring = false;
}
@Override
- public void setGlobalBeanFactory(GlobalBeanFactory globalBeanFactory) {
- this.globalBeanFactory = globalBeanFactory;
+ public Bean factoryBean(ApplicationContext applicationContext) {
+ if (springBeanFactory != null) {
+ return springBeanFactory.getBean(beanClass);
+ }
+ try {
+ return getObject();
+ } catch (Exception e) {
+ logger.error("", e);
+ throw new BeanCreatedException(e);
+ }
}
@Override
- public Bean getBean() {
+ public Bean factoryNamedBean(String name, ApplicationContext applicationContext) {
if (springBeanFactory != null) {
- return springBeanFactory.getBean(beanClass);
+ return springBeanFactory.getBean(name, beanClass);
}
try {
return getObject();
@@ -92,7 +86,12 @@ public Bean getBean() {
}
@Override
- public Class getBeanType() {
+ public boolean isCreated() {
+ return false;
+ }
+
+ @Override
+ public Class getBeanClass() {
return beanClass;
}
@@ -108,11 +107,9 @@ public void setBeanFactory(@NonNull org.springframework.beans.factory.BeanFactor
@Override
public Bean getObject() throws Exception {
if (!isCreateBySpring) {
- BeanInfo beanInfo = debbieBeanInfoFactory.getBeanInfo(name, getBeanType(), false, false);
- if (beanInfo != null && beanInfo.getBeanClass().isInterface()) {
- return globalBeanFactory.factoryBeanByDependenceProcessor(beanInfo, false);
- } else if (beanInfo != null && !beanInfo.getBeanClass().isInterface()) {
- return globalBeanFactory.factoryBeanByDependenceProcessor(beanInfo, true);
+ BeanInfo beanInfo = debbieBeanInfoFactory.getBeanInfo(name, getBeanClass(), false, false);
+ if (beanInfo instanceof BeanFactory beanFactory) {
+ return beanFactory.factoryNamedBean(name, applicationContext);
}
}
return null;
@@ -123,17 +120,13 @@ public Class> getObjectType() {
return beanClass;
}
- public void setSingleton(boolean singleton) {
- this.singleton = singleton;
- }
-
@Override
public boolean isSingleton() {
return singleton;
}
@Override
- public void destroy() {
+ public void destruct(ApplicationContext applicationContext) {
// destory
}
}
diff --git a/boot/spring/src/main/java/com/truthbean/debbie/spring/SpringBeanFactory.java b/boot/spring/src/main/java/com/truthbean/debbie/spring/SpringBeanFactory.java
new file mode 100644
index 0000000..4245666
--- /dev/null
+++ b/boot/spring/src/main/java/com/truthbean/debbie/spring/SpringBeanFactory.java
@@ -0,0 +1,89 @@
+package com.truthbean.debbie.spring;
+
+import com.truthbean.debbie.bean.BeanFactory;
+import com.truthbean.debbie.bean.BeanType;
+import com.truthbean.debbie.bean.NonBean;
+import com.truthbean.debbie.core.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author TruthBean
+ * @since 0.5.3
+ * Created on 2021/12/19 00:47.
+ */
+@NonBean
+public class SpringBeanFactory implements BeanFactory