我们已经将 spring boot(v1.5.1)-jpa 应用程序配置为指向 HikariCP,但由于一些奇怪的原因,应用程序仍然指向 tomcat-jdbc 池,这是 spring-boot 使用的默认值,而不是 Hikari-CP。我已经提到了下面使用的配置。
更新
现在当 HikariCP 尝试加载时进行更改后,我们得到 SQLNotSupportedFeature 异常。请注意,我们将 Springboot-JPA-Hibernate 与 hikari 结合使用。
任何帮助表示赞赏。
摇篮
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.3.2'
// Exclusions
compile('org.springframework.boot:spring-boot-starter-web'){
exclude module: "spring-boot-starter-tomcat"
}
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jdbc") {
exclude module: "spring-boot-starter-tomcat"
}
//spring integration
compile("org.springframework.boot:spring-boot-starter-integration"){
exclude module: "spring-boot-starter-tomcat"
}
应用程序属性
hibernate.show.sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.datasource.hikari.maximum-pool-size=50
spring.datasource.hikari.idle-timeout=1000
spring.datasource.hikari.pool-name=pooool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:oracle:thin:@<hostname>:1521/<instance>
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
数据配置
我们使用 Spring JPA 休眠组合以及 PCF(Pivotal Cloud Foundry)进行配置。
public class DataSourceConfiguration {
@Value("${spring.datasource.hikari.maximum-pool-size}")
private int maxSize;
@Value("${spring.datasource.hikari.idle-timeout}")
private String idleTimeout;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName;
@Bean("destroyMethod=close")
@Primary
public DataSource dataSource() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setUrl(url);
dataSource.setPassword(password);
dataSource.setUsername(username);
dataSource.setDriverClassName(driverClassName);
dataSource.setValidationQuery(idleTimeout);
dataSource.setMaxIdle(maxSize);
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
System.err.println("POOLSIZE----> " +dataSource.getPoolSize());
System.err.println("POOLNAME----> " +dataSource.getName());
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource);
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactoryBean.setPackagesToScan(applicationPropertiesConfig.getPackagestoScan());
Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.dialect", applicationPropertiesConfig.getHibernateDialect());
jpaProperties.put("hibernate.show_sql", applicationPropertiesConfig.getHibernateShowSQL());
entityManagerFactoryBean.setJpaProperties(jpaProperties);
return entityManagerFactoryBean;
}
/**
* Declaration of the transaction manager.
*
* @param entityManagerFactory the entity manager factory
* @return an instance of JpaTransactionManager
*/
@Bean
JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
请帮忙,因为这会阻止我们的应用程序并且令人沮丧。提前致谢。