mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
commit
426d2352e9
@ -241,6 +241,30 @@ public class FlexGlobalConfig {
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定默认全局配置(允许手动。在多源时,方便由注解指定默认源)
|
||||
*
|
||||
* <code><pre>
|
||||
* @Configuration
|
||||
* public class Config{
|
||||
* @Bean(value = "db1", typed = true) //默认
|
||||
* public DataSource db1(@Inject("${demo.db1}") HikariDataSource ds) {
|
||||
* return ds;
|
||||
* }
|
||||
*
|
||||
* @Bean("db2")
|
||||
* public DataSource db1(@Inject("${demo.db2}") HikariDataSource ds) {
|
||||
* return ds;
|
||||
* }
|
||||
* }
|
||||
* </pre></code>
|
||||
*
|
||||
* @param config 全局配置
|
||||
*/
|
||||
public static void setDefaultConfig(FlexGlobalConfig config) {
|
||||
defaultConfig = config;
|
||||
}
|
||||
|
||||
public static FlexGlobalConfig getConfig(Configuration configuration) {
|
||||
return getConfig(configuration.getEnvironment().getId());
|
||||
}
|
||||
@ -249,9 +273,21 @@ public class FlexGlobalConfig {
|
||||
return globalConfigs.get(environmentId);
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void setConfig(String id, FlexGlobalConfig config) {
|
||||
setConfig(id, config, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置全局配置
|
||||
*
|
||||
* @param id 环境id
|
||||
* @param config 全局配置
|
||||
* @param autoDefault 自动指定默认全局配置(在多源时,方便由注解指定默认源)
|
||||
*/
|
||||
public static synchronized void setConfig(String id, FlexGlobalConfig config, boolean autoDefault) {
|
||||
//first setConfig,copy the config to default
|
||||
if (globalConfigs.isEmpty()) {
|
||||
if (autoDefault && globalConfigs.isEmpty()) {
|
||||
|
||||
defaultConfig.setSqlSessionFactory(config.sqlSessionFactory);
|
||||
defaultConfig.setDbType(config.dbType);
|
||||
@ -267,6 +303,4 @@ public class FlexGlobalConfig {
|
||||
|
||||
globalConfigs.put(id, config);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -32,6 +32,8 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
||||
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
||||
factoryBuilderPlus = bean;
|
||||
});
|
||||
|
||||
initAfter(dsWrap);
|
||||
}
|
||||
|
||||
protected MybatisAdapterFlex(BeanWrap dsWrap, Props dsProps) {
|
||||
@ -42,6 +44,16 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
||||
dsWrap.context().getBeanAsync(FlexSqlSessionFactoryBuilder.class, bean -> {
|
||||
factoryBuilderPlus = bean;
|
||||
});
|
||||
|
||||
initAfter(dsWrap);
|
||||
}
|
||||
|
||||
protected void initAfter(BeanWrap dsWrap) {
|
||||
globalConfig.setSqlSessionFactory(getFactory());
|
||||
|
||||
if (dsWrap.typed()) {
|
||||
FlexGlobalConfig.setDefaultConfig(globalConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,8 +63,6 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
||||
|
||||
@Override
|
||||
protected void initConfiguration(Environment environment) {
|
||||
|
||||
|
||||
//for configuration section
|
||||
config = new FlexConfiguration(environment);
|
||||
|
||||
@ -72,7 +82,8 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault {
|
||||
Utils.injectProperties(globalConfig, globalProps);
|
||||
}
|
||||
globalConfig.setConfiguration(config);
|
||||
FlexGlobalConfig.setConfig(environment.getId(), globalConfig);
|
||||
|
||||
FlexGlobalConfig.setConfig(environment.getId(), globalConfig, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user