使用 spring-data-jpa 和完整的 tomcat-jdbc 配置的 spring boot 为 ResetAbandonedTimer 抛出 java.lang.ClassNotFound
Posted
技术标签:
【中文标题】使用 spring-data-jpa 和完整的 tomcat-jdbc 配置的 spring boot 为 ResetAbandonedTimer 抛出 java.lang.ClassNotFoundException【英文标题】:spring boot with spring-data-jpa and full tomcat-jdbc config throws java.lang.ClassNotFoundException for ResetAbandonedTimer 【发布时间】:2016-02-23 06:53:48 【问题描述】:我正在使用带有以下 pom 依赖项的 spring boot 1.3.0.RELEASE
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我正在尝试让 JPA 正常工作,并且在我的 application.properties 中使用以下内容一切正常
# Connection url for the database
spring.datasource.url = jdbc:oracle:thin:@**********
# Username and password
spring.datasource.username = **********
spring.datasource.password = *********
当我为 tomcat-jdbc 切换到完整的 dbcp 配置时,如下所示:
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@**********
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.initial-size=0
spring.datasource.max-active=10
spring.datasource.default-auto-commit=true
spring.datasource.default-transaction-isolation=2
spring.datasource.fair-queue=false
spring.datasource.jdbc-interceptors=ConnectionState;StatementFinalizer;ResetAbandonedTimer"
spring.datasource.jmx-enabled=true
spring.datasource.log-abandoned=true
spring.datasource.max-idle=1
spring.datasource.max-wait=30000
spring.datasource.min-evictable-idle-time-millis=60000
spring.datasource.min-idle=1
spring.datasource.remove-abandoned=true
spring.datasource.remove-abandoned-timeout=300
spring.datasource.test-on-borrow=true
spring.datasource.test-on-return=false
spring.datasource.test-while-idle=false
spring.datasource.time-between-eviction-runs-millis=10000
spring.datasource.use-equals=false
spring.datasource.validation-interval=60000
spring.datasource.validation-query=SELECT 2+2 FROM DUAL
我得到以下堆栈跟踪
2015-11-20 16:58:18.788 ERROR 48307 --- [nio-8080-exec-1] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to inform interceptor of pool start.
java.lang.ClassNotFoundException: Unable to load class: org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer" from ClassLoader:java.net.URLClassLoader@5bbcaf22;ClassLoader:TomcatEmbeddedWebappClassLoader
context: ROOT
delegate: true
----------> Parent Classloader:
java.net.URLClassLoader@5bbcaf22
at org.apache.tomcat.jdbc.pool.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:56) ~[tomcat-jdbc-8.0.28.jar:na]
at org.apache.tomcat.jdbc.pool.PoolProperties$InterceptorDefinition.getInterceptorClass(PoolProperties.java:964) ~[tomcat-jdbc-8.0.28.jar:na]\
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:447) [tomcat-jdbc-8.0.28.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:141) [tomcat-jdbc-8.0.28.jar:na]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:115) [tomcat-jdbc-8.0.28.jar:na]
......
......
......
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.java:74) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_20]
at java.lang.Class.forName(Class.java:340) ~[na:1.8.0_20]
at org.apache.tomcat.jdbc.pool.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:38) ~[tomcat-jdbc-8.0.28.jar:na]
... 147 common frames omitted
即使使用不同的 spring boot 版本似乎也是如此.... 我的配置(取自我们已经正常使用的 spring 数据源 bean)不是启动所期望的吗?
干杯
【问题讨论】:
【参考方案1】:错字。
从最后的spring.datasource.jdbc-interceptors=ConnectionState;StatementFinalizer;ResetAbandonedTimer"
中删除"
。
【讨论】:
我很感激你!逆天!经过这么多年的发展,您会认为被拼写错误咬伤的日子已经一去不复返了……非常感谢!很抱歉浪费了字节! 我很高兴为您提供帮助 ;)以上是关于使用 spring-data-jpa 和完整的 tomcat-jdbc 配置的 spring boot 为 ResetAbandonedTimer 抛出 java.lang.ClassNotFound的主要内容,如果未能解决你的问题,请参考以下文章
为什么Spring-Data-JPA Async无法正常工作?
spring-boot与spring-data-JPA的简单集成使用
Maven 使用 spring-data-jpa 和 querydsl 构建问题