@Configuration
@ConditionalOnProperty(name="spring.datasource.dbs.enable",
havingValue="true")
@ConditionalOnClass(value=com.alibaba.druid.pool.DruidDataSource.class)
@AutoConfigureBefore(value=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(value={com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties.class,org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.class})
@EnableAutoConfiguration(exclude={com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.class,org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration.class})
@Import(value={com.alibaba.druid.spring.boot.autoconfigure.stat.DruidSpringAopConfiguration.class,com.alibaba.druid.spring.boot.autoconfigure.stat.DruidStatViewServletConfiguration.class,com.alibaba.druid.spring.boot.autoconfigure.stat.DruidWebStatFilterConfiguration.class,com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration.class})
public class DataSourceConfig
extends java.lang.Object
构造器和说明 |
---|
DataSourceConfig() |
限定符和类型 | 方法和说明 |
---|---|
DynamicRoutingDataSource |
dynamicRoutingDataSource(javax.sql.DataSource masterDs)
动态数据源
|
java.util.Map<java.lang.String,com.alibaba.druid.pool.DruidDataSource> |
getDbs()
其他库数据源
|
javax.sql.DataSource |
getMasterDataSource() |
org.springframework.jdbc.core.JdbcTemplate |
jdbcTemplate(javax.sql.DataSource dataSource) |
org.springframework.jdbc.datasource.DataSourceTransactionManager |
userTransactionManager(javax.sql.DataSource dataSource) |
@Bean(name="masterDataSource", initMethod="init") @Primary public javax.sql.DataSource getMasterDataSource() throws java.sql.SQLException
java.sql.SQLException
public java.util.Map<java.lang.String,com.alibaba.druid.pool.DruidDataSource> getDbs() throws java.sql.SQLException
java.sql.SQLException
@Bean(name="dynamicDataSource") public DynamicRoutingDataSource dynamicRoutingDataSource(javax.sql.DataSource masterDs) throws java.sql.SQLException
java.sql.SQLException
@Primary @Bean public org.springframework.jdbc.datasource.DataSourceTransactionManager userTransactionManager(@Qualifier(value="dynamicDataSource") javax.sql.DataSource dataSource)
@Bean public org.springframework.jdbc.core.JdbcTemplate jdbcTemplate(@Qualifier(value="dynamicDataSource") javax.sql.DataSource dataSource)