无法访问Spring引导应用程序的多个数据模式和@Primary的替代方案

时间:2016-09-22 10:40:15

标签: mysql spring spring-boot

我在弹簧启动时连接两个不同的架构(MySQL)时出现问题,我不应该使用@primary进行声明,我需要更改而不是@primary。

#first db
spring.datasource.url = [url]
spring.datasource.username = [username]
spring.datasource.password = [password]
spring.datasource.driverClassName = oracle.jdbc.OracleDriver

#second db ...
spring.secondDatasource.url = [url]
spring.secondDatasource.username = [username]
spring.secondDatasource.password = [password]
spring.secondDatasource.driverClassName = oracle.jdbc.OracleDriver


@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
}

@Bean
@ConfigurationProperties(prefix="spring.secondDatasource")
public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
}

这里我不允许使用@Primary ......

0 个答案:

没有答案