我们已经配置了我们的spring引导(v1.5.1)-jpa应用程序来指向HikariCP,但仍然由于一些奇怪的原因,应用程序仍然指向tomcat-jdbc pool,默认由弹簧引导而不是Hikari-CP使用。 我已经提到了下面使用的配置。Spring引导JPA应用程序不与HikariCP配置一起工作
更新
现在正在变化的时候,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"
}
application.properties
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
Dataconfiguration
我们正在使用Spring JPA冬眠配置结合PCF沿(枢纽的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;
}
请帮助,因为这阻止了我们的应用程序,是令人沮丧的。 在此先感谢。
我假设你的Hikari-CP在你的依赖关系中是正确的?确保你明确地从POM中排除了tomcat-jdbc。 https://www.mkyong.com/spring-boot/spring-boot-jdbc-mysql-hikaricp-example/ –
对不起,我忘了提前它。是的,我们确实增加了排除,但它是没有用的。 – Guru
比较你的项目与我自己的项目,我知道正在与HikaryCP合作。我看到的唯一不同就是你没有一个司机。也许这没有被拾起。尝试添加这个依赖关系 编译组:'oracle',名称:'ojdbc6',版本:'11 .2.0.3' –