refactor: 优化配置

This commit is contained in:
zhouhao
2024-07-08 14:41:30 +08:00
parent 87f7f06e7d
commit f5d46643e9
15 changed files with 104 additions and 123 deletions

View File

@@ -31,7 +31,7 @@ import static org.hswebframework.web.datasource.strategy.AnnotationDataSourceSwi
* @author zhouhao
* @since 3.0
*/
@Configuration
@Configuration(proxyBeanMethods = false)
public class AopDataSourceSwitcherAutoConfiguration {
@Bean

View File

@@ -1,13 +1,9 @@
package org.hswebframework.web.datasource;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author zhouhao
@@ -22,24 +18,5 @@ public class DynamicDataSourceAutoConfiguration {
return new HswebDataSourceProperties();
}
@Bean
public BeanPostProcessor switcherInitProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof DynamicDataSourceService) {
DataSourceHolder.dynamicDataSourceService = ((DynamicDataSourceService) bean);
}
return bean;
}
};
}
}