在我的项目中,我们使用的是spring boot 2.0.3.Release。我们已经配置了多个数据源,默认情况下,Spring Boot选择Hikari数据源作为连接池。下面是我的代码。
应用程序.属性
first.datasource.jdbcUrl=jdbc:sqlserver://localhost:1433;databaseName=test1
first.datasource.username=admin
first.datasource.password=admin
first.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDeriver
first.datasource.hikari.maximumlPoolSize=50
# Second Datasource
second.datasource.jdbcUrl=jdbc:postgresql://db-server-bar:5432/test2
second.datasource.username=admin
second.datasource.password=admin
second.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDeriver
second.datasource.hikari.maximumlPoolSize=50
第一配置.java
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactory",
basePackages = { "com.org.first.repo" }
)
public class FirstConfig {
@Primary
@Bean(name = "dataSource")
@ConfigurationProperties(prefix = "first.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean
entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("dataSource") DataSource dataSource
) {
return builder
.dataSource(dataSource)
.packages("com.org.first.entity")
.persistenceUnit("first")
.build();
}
@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory
entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory);
}
}
配置未选取我在属性文件中设置的最大池大小。当我签入显示为10的数据源对象时。如何覆盖在光数据源中设置的默认值?
翻过高山走不出你
长风秋雁
相关分类