org.zodiac.autoconfigure.datasource.jdbc.JdbcDataSourceRuleAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.datasource.jdbc;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.zodiac.autoconfigure.datasource.condition.ConditionalOnDataSourceEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.commons.util.Colls;
import java.util.Map;
@SpringBootConfiguration
@ConditionalOnDataSourceEnabled
//@EnableConfigurationProperties(DataSourceProperties.class)
//@AutoConfigureBefore(value = {DataSourceAutoConfiguration.class})
//@AutoConfigureAfter(value = {JdbcDataSourcePoolAutoConfiguration.class})
@ConditionalOnClass(name = {"org.zodiac.datasource.jdbc.config.DataSourceRuleInfo", "org.zodiac.datasource.jdbc.util.DataSourceUtil"})
@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_DATASOURCE_JDBC_RULES_ENABLED, havingValue = "true", matchIfMissing = true)
public class JdbcDataSourceRuleAutoConfiguration implements EnvironmentAware, ApplicationContextAware {
private ApplicationContext applicationContext;
/*数据源链接池binding信息*/
private Map dataSourcePoolBindings = Colls.linkedMap();
/*数据源规则binding信息*/
private Map dataSourceRuleBindings = Colls.linkedMap();
private Environment environment;
public JdbcDataSourceRuleAutoConfiguration() {
}
@Override
public final void setEnvironment(final Environment environment) {
this.environment = environment;
this.dataSourcePoolBindings = org.zodiac.datasource.jdbc.util.DataSourceUtil.getDruidDataSourcePoolBindings(this.environment);
this.dataSourceRuleBindings = org.zodiac.datasource.jdbc.util.DataSourceUtil.getDataSourceRuleBindings(this.environment);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}