我已使用以下设置配置了连接池。应用程序似乎表现异常。当应用程序在tomcat上运行时,我无法使用sqldeveloper或任何sql客户端更新任何表。我在oracle企业管理器中看到争用锁。应用程序使用的是hikaricp 2.4.6,oracle 11g,spring数据jpa和hibernate 5.2.9.Final
db.connection.maximumPoolSize=30
db.connection.minimumIdleConnections=10
db.connection.leakDetectionThreshold=2000
db.connection.idleTimeout=600000
db.connection.maxLifetime=1800000
@Configuration
@EnableJpaRepositories(basePackages = "test.api.repositories")
@EnableTransactionManagement
@Slf4j
@EnableCaching
public class JpaConfiguration {
@Autowired
private DatabaseProperties databaseProperties;
@Value("${spring.cache.caffeine.spec:maximumSize=2000,expireAfterWrite=600s,expireAfterAccess=300s}")
private String cacheSpecs;
@Bean
public HikariDataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setConnectionTestQuery("SELECT 1 FROM DUAL");
config.setPoolName("test-pool");
config.setDriverClassName(databaseProperties.getConnection().getDriver());
config.setJdbcUrl(databaseProperties.getConnection().getUrl());
config.setUsername(databaseProperties.getConnection().getUsername());
config.setPassword(databaseProperties.getConnection().getPassword());
config.setMaximumPoolSize(databaseProperties.getConnection().getMaximumPoolSize());
config.setMinimumIdle(databaseProperties.getConnection().getMinimumIdleConnections());
config.setLeakDetectionThreshold(databaseProperties.getConnection().getLeakDetectionThreshold());
config.setIdleTimeout(databaseProperties.getConnection().getIdleTimeout());
config.setMaxLifetime(databaseProperties.getConnection().getMaxLifetime());
config.setRegisterMbeans(true);
return new HikariDataSource(config);
}
@Bean
public HibernateJpaVendorAdapter hibernateJpaVendorAdapter() {
return new HibernateJpaVendorAdapter();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final Properties properties = new Properties();
final LocalContainerEntityManagerFactoryBean lC = new LocalContainerEntityManagerFactoryBean();
lC.setDataSource(dataSource());
lC.setJpaVendorAdapter(hibernateJpaVendorAdapter());
lC.setPackagesToScan(databaseProperties.getHibernate().getPackagesToScan());
properties.setProperty("hibernate.hbm2ddl.auto", databaseProperties.getHibernate().getHbm2ddl());
properties.setProperty("hibernate.dialect", databaseProperties.getHibernate().getDialect());
properties.setProperty("hibernate.jdbc.batch_size", databaseProperties.getHibernate().getBatchSize());
properties.setProperty("hibernate.default_schema", databaseProperties.getHibernate().getDefaultSchema());
properties.setProperty("hibernate.show_sql", String.valueOf(databaseProperties.getHibernate().isShowSql()));
properties.setProperty("hibernate.cache.use_second_level_cache", String.valueOf(databaseProperties.getHibernate().isUseSecondLevelCache()));
properties.setProperty("hibernate.cache.use_query_cache", String.valueOf(databaseProperties.getHibernate().isUseQueryCache()));
properties.setProperty("hibernate.cache.region.factory_class", databaseProperties.getHibernate().getCacheFactoryClass());
properties.setProperty("javax.persistence.sharedCache.mode", databaseProperties.getHibernate().getSharedCacheMode());
properties.setProperty("hibernate.connection.characterEncoding", databaseProperties.getHibernate().getCharacterEncoding());
properties.setProperty("hibernate.connection.CharSet", databaseProperties.getHibernate().getCharSet());
properties.setProperty("hibernate.connection.useUnicode", databaseProperties.getHibernate().getUseUnicode());
properties.setProperty("hibernate.connection.defaultNChar", databaseProperties.getHibernate().getConnectionDefaultNChar());
lC.setJpaProperties(properties);
return lC;
}