JDBCConnectionException.无法获取JDBC连接。无法获取JDBC连接

问题描述 投票:0回答:1

我已经看到很多关于此类问题的帖子,但我还没有得到合适的解决方案。

我有一个Spring引导程序,每天定期从其他源调用。最近,我们看到JDBCConnectionException

下面是错误的stackTrace

WARN o.h.e.jdbc.spi.SqlExceptionHelper@logExceptions:137 - SQL Error: 0, SQLState: null
ERROR o.h.e.jdbc.spi.SqlExceptionHelper@logExceptions:142 - HikariPool-1 - Connection is not available, request timed out after 928162ms.
ERROR c.w.locationmaster.service.DBService@getAllCustomers:110 - 
Exception in getAllCustomers(): Exception org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection; 
nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection, stackTrace 
[org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:275), 
org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253), 
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527), 
org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61), 
org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242), 
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke

我用的是

Springboot 2.1.6
gradle-5.4.1

Gradle:

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'jdepend'

sourceCompatibility = 1.11

bootJar {
    baseName = 'customers-service'
}

checkstyle {
    ignoreFailures = true
    toolVersion = '8.2'
    configDir = file("$rootProject.projectDir/etc/checkstyle")
    System.setProperty('checkstyle.cache.file', String.format('%s/%s', buildDir, 'checkstyle.cachefile'))
}

repositories {
    mavenCentral()
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter')
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.springframework.boot:spring-boot-starter-mail'
    compile 'org.springframework.boot:spring-boot-starter-web'

    compile('org.springframework.boot:spring-boot-starter-jdbc') {
        exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
    }
    compile('com.fasterxml.jackson.core:jackson-annotations:2.9.4')
    compile('com.fasterxml.jackson.core:jackson-databind:2.9.4')

    compile('org.apache.httpcomponents:httpclient:4.3.4')

    compile('org.apache.commons:commons-lang3:3.5')
    compile('org.apache.commons:commons-collections4:4.0')

    testCompile('org.springframework.boot:spring-boot-starter-test')
    runtime('com.microsoft:sqljdbc4:4.0') {
        exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
    }
}

应用程序.属性

server.servlet.context-path=/customers
server.port=XXXX

spring.security.user.name=XXXX
spring.security.user.password=XXXX

management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
management.health.ldap.enabled=false
management.endpoints.web.cors.allow-credentials=true

spring.datasource.url=jdbc:sqlserver://XXXX;databaseName=XXX
spring.datasource.username=XXXX
spring.datasource.password=XXXX
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.platform=sqlserver

spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2014Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy

spring.datasource.validation-query=select 1
spring.datasource.testOnBorrow=true

我有一个@Repository类和一个方法,其内容为

@Transactional(readOnly = true) 

来检索数据库中的记录,是@事务性导致的问题吗?

请教我。先谢谢你

java spring-data-jpa hikaricp
1个回答
1
投票

这不是@Transactional,它甚至没有达到这个点。

你的应用程序不能建立DB连接。

HikariPool-1 - Connection is not available, request timed out

这一定是DB池配置的问题(错误的DB url?

© www.soinside.com 2019 - 2024. All rights reserved.