标签:nbsp config private autowired new component auto jdb class
spring.second-datasource.driver-class-name= spring.second-datasource.jdbc-url= spring.second-datasource.username= spring.second-datasource.password= #注意jdbc-url与url的区别: spring.datasource.driver-class-name= spring.datasource.jdbc-url= spring.datasource.username= spring.datasource.password
@Configuration public class DataSourceConfiguration { @Bean @Primary @ConfigurationProperties(prefix = "spring.datasource") public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "datasourceB") @ConfigurationProperties(prefix = "spring.second-datasource") public DataSource secondDataSource() { return DataSourceBuilder.create().build(); } }
@DimModule @Component public class TestModule implements SpringModule { @Autowired private DataSource dataSource = null; @Autowired @Qualifier("datasourceB ") private DataSource datasourceB = null; @Override public void loadModule(ApiBinder apiBinder) throws Throwable { apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource)); //默认数据源 apiBinder.installModule(new JdbcModule(Level.Full, "datasourceB ", this.datasourceB )); // 数据源B} }
标签:nbsp config private autowired new component auto jdb class
原文地址:https://www.cnblogs.com/nachdenken/p/13065310.html