简体   繁体   English

Spring Boot JPA应用程序不适用于HikariCP配置

[英]Spring boot JPA application NOT working with HikariCP configuration

We have configured our spring boot(v1.5.1)-jpa application to point to HikariCP but still due to some weird reason the application is still pointing to tomcat-jdbc pool, the default used by spring-boot instead of Hikari-CP. 我们已将spring boot(v1.5.1)-jpa应用程序配置为指向HikariCP,但由于某些奇怪的原因,该应用程序仍指向tomcat-jdbc池,该池是spring-boot而不是Hikari-CP使用的默认池。 I have mentioned the configuration used below. 我已经提到了下面使用的配置。

Updates 更新
After making changes now when the HikariCP is trying to load we are getting the SQLNotSupportedFeature Exception. 现在,在尝试加载HikariCP进行更改之后,我们得到了SQLNotSupportedFeature异常。 Do note that we are using Springboot-JPA-Hibernate combination along with hikari. 请注意,我们正在使用Springboot-JPA-Hibernate组合和hikari。

Any help is appreciated. 任何帮助表示赞赏。

Gradle 摇篮

    // 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 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 Dataconfiguration

We are using Spring JPA hibernate combination for configuration along with PCF (Pivotal Cloud Foundry). 我们将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;
            }

Please help as this is blocking our application and is frustrating. 请帮助,因为这阻止了我们的应用程序并且令人沮丧。 Thanks in advance. 提前致谢。

您应该在bean中使用new HikariDataSource(.....)而不要使用new DataSource()

Your gradle should have following config for hikari: 您的gradle应该具有针对hikari的以下配置:

configurations {
     compile.exclude module: "tomcat-jdbc"
}

dependencies {
     compile("org.springframework.boot:spring-boot-starter-jdbc")
     compile group: 'com.zaxxer', name: 'HikariCP', version: '2.6.3'
}

Above will exclude tomcat-jdbc and will create connection pool using hikari. 上面将排除tomcat-jdbc,并使用hikari创建连接池。 Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM