我的应用程序中有这些属性:
spring.first.datasource.jdbc-url=jdbc:oracle:thin:first-datasource-url
spring.first.datasource.username=user1
spring.first.datasource.password=pass1
spring.first.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.second.datasource.jdbc-url=jdbc:oracle:thin:second-datasource-url
spring.second.datasource.username=user2
spring.second.datasource.password=pass2
spring.second.datasource.driver-class-name=oracle.jdbc.OracleDriver
问题是一个db与ojdbc6兼容,另一个与ojbc8兼容。有没有什么方法可以使每个数据源配置的版本或jar显式化?
这是我的配置文件:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "firstEntityManagerFactory",
transactionManagerRef = "firstTransactionManager",
)
public class FirstConfiguration {
@Bean(name = "firstDataSource")
@ConfigurationProperties(prefix = "spring.first.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "firstEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean barEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("firstDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).build();
}
@Bean(name = "firstTransactionManager")
public PlatformTransactionManager firstTransactionManager(
@Qualifier("firstEntityManagerFactory") EntityManagerFactory firstEntityManagerFactory) {
return new JpaTransactionManager(firstEntityManagerFactory);
}
@Bean(name = "firstJdbcTemplate")
public JdbcTemplate jdbcTemplateFirst(@Qualifier("firstDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
}
1条答案
按热度按时间oalqel3c1#
对于ojdbc6.jar文件,驱动程序类名为
oracle.jdbc.OracleDriver
对于ojdbc8,驱动程序类名为oracle.jdbc.driver.OracleDriver
您可以看到这两个类的区别,因此我认为只要类名不同,您就可以在应用程序中使用这两个jar文件。我假设对于ojdbc6.jar,属性名可以是
对于ojdbc8.jar,它将