Springboot - 包括 JPA 依赖项并运行“mvn clean install”失败,HikariPool-1 - 池初始化期间出现异常

Posted

技术标签:

【中文标题】Springboot - 包括 JPA 依赖项并运行“mvn clean install”失败,HikariPool-1 - 池初始化期间出现异常【英文标题】:Springboot -Include JPA dependency and run "mvn clean install" fails with HikariPool-1 - Exception during pool initialization 【发布时间】:2019-04-29 02:58:37 【问题描述】:

Springboot 版本 2.0.6.RELEASE +JPA

为什么要尝试创建 Datasource bean。

Hibernate 和 Oracle 的属性

spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

我尝试了什么

 - @SpringBootApplication( exclude=DataSourceAutoConfiguration.class)
 - @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
 - Create New @Configuration Datasouce @bean ,with JPA properties and Create Datasoucetest class with in memory DB.
- mvn clean instal -DskipTests --- **this works fine but i want my others tests to run.**

包含依赖

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc7</artifactId>
                <version>$ojdbc.version</version>
     </dependency>

错误日志

[HikariDataSource]-[110 ]-HikariPool-1 - Starting... 
[2018-11-27T16:30:43,541+0530]-[ERROR]-[realmId=,tid=]-[HikariPool]-[567 ]-HikariPool-1 - Exception during pool initialization. java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$c1fb58c0.getConnection(<generated>)
    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:166)
    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:111)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27.CGLIB$jpaVendorAdapter$6(<generated>)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27$$FastClassBySpringCGLIB$$f6c0d4d0.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27.jpaVendorAdapter(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)

我参考过的帖子

Unable to connect to oracle database.It says "Unable to determine jdbc url from datasource"

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

Cannot load configuration class in Spring with Oracle db connection

hibernate dialect for oracle 12c

【问题讨论】:

能否请您也检查一下接下来的事情来澄清这个问题:* 数据库没有运行 * 你的 URL 错误 * 有防火墙。 我的数据库托管在 AWS 中,因此无法访问数据库主机。有什么办法根本不创建 Datasource bean? 可以通过sqlplus连接数据库吗?通过使用下一个命令:sqlplus username/password@host:port/service 所以设置是这样的。我的应用程序在 1 个 AWS 账户中,我的数据库是另一个 AWS 账户,有一个桥创建,其中 DB 主机将只接受来自应用程序 aws 主机的请求。因此,当我在本地编码时,我不希望创建 DB Bean 并运行测试。 【参考方案1】:

我可以向您展示我的配置,它对我有用,它在几分钟前检查过,唯一的区别是 oracle 驱动程序。

spring-boot v.2.0.1.RELEASE

pom.xml

<dependency>
   <groupId>oracle</groupId>
   <artifactId>ojdbc6</artifactId>
   <version>11.2.0.1</version>
</dependency>

Oracle配置

@Configuration
@ConfigurationProperties
public class OracleConfiguration 

    private static Logger log = LoggerFactory.getLogger(OracleConfiguration.class);

    @Value("$oracle.username")
    private String username;
    @Value("$oracle.password")
    private String password;
    @Value("$oracle.url")
    private String url;

    @Bean
    DataSource dataSource() throws SQLException
        log.info("Init production profile for OracleConfiguration");
        OracleDataSource dataSource = new OracleDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setURL(url);
        dataSource.setImplicitCachingEnabled(true);
        dataSource.setFastConnectionFailoverEnabled(true);
        return dataSource;
    

application.properties

oracle.username=username
oracle.password=password
oracle.url=jdbc:oracle:thin:@//db.yourdomain.com:1524/DB
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

你可以查看这个答案https://***.com/a/12574926/1063509

数据库未运行 你的网址有误 有防火墙挡道。

【讨论】:

我使用了 H2 In-Memory DB 并建立了与它的连接以进行测试。这样本地部署的问题就会得到解决。【参考方案2】:

您的网址有不相关的双斜杠(当您删除用户和密码时),更改为:

spring.datasource.url=jdbc:oracle:thin:@earth-db-11:5121/stardev

【讨论】:

【参考方案3】:

您好,请尝试在 mysql 工作台或 toad for mysql 中更改您的密码。

【讨论】:

以上是关于Springboot - 包括 JPA 依赖项并运行“mvn clean install”失败,HikariPool-1 - 池初始化期间出现异常的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot安装及初步介绍

springBoot整合JPA

SpringBoot 与 JPA

弹簧状态机数据 jpa 示例问题

SpringBoot整合JPA

我使用 Springboot。 spring-boot-starter-data-jpa 依赖于 log4j。它脆弱吗?