1.5.1バージョンのスプリングブートを使用するアプリケーションに問題があります。 - MySQLのデータソーススプリングブート複数のデータソース
@Configuration
public class OracleDBConfig {
@Bean(name = "oracleDb")
@ConfigurationProperties(prefix = "spring.ds_oracle")
public DataSource oracleDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "oracleJdbcTemplate")
public JdbcTemplate oracleJdbcTemplate(@Qualifier("oracleDb") DataSource dsOracle) {
return new JdbcTemplate(dsOracle);
}
}
のOracleデータソース
@Configuration :
私のアプリケーションは、2つのデータベース(OracleやMySQLの)
私のアプリケーションの使用2つのデータソースと通信する必要がありますパブリッククラスMySQLDBConfig {
@Bean(name = "mysqlDb") @ConfigurationProperties(prefix = "spring.ds_mysql") public DataSource mysqlDataSource() { return DataSourceBuilder.create().build(); } @Bean(name = "mysqlJdbcTemplate") public JdbcTemplate mySQLjdbcTemplate(@Qualifier("mysqlDb")DataSource dsMySQL) { return new JdbcTemplate(dsMySQL); } }
私は接頭辞を使用することによって、私のapplications.properties中2つのデータソースを定義しています。
私はこのエラーを持っているプログラムを起動する場合:
Parameter 0 of method oracleJdbcTemplate in com.bv.aircraft.config.OracleDBConfig required a single bean, but 2 were found:
- mysqlDb: defined by method 'mysqlDataSource' in class path resource [com/bv/aircraft/config/MySQLDBConfig.class]
- oracleDb: defined by method 'oracleDataSource' in class path resource [com/bv/aircraft/config/OracleDBConfig.class]
を私は@Primaryを使用しようとしましたが、私は他のデータソースを使用する必要がある場合、それは動作しません。
はどちらかあなた
を? –