gradle bootRun:应用程序无法使用类路径启动

Posted

技术标签:

【中文标题】gradle bootRun:应用程序无法使用类路径启动【英文标题】:gradle bootRun: application fail to start with classpath 【发布时间】:2015-12-10 13:08:10 【问题描述】:

我是 gradle 和 spring boot 的新手。最近我创建了一个项目,它使用了 spring boot、spring websocket、spring jdbc 和其他一些 jar 依赖项。完整的build.gradle如下:

buildscript 
    repositories 
        mavenCentral()
        mavenLocal()
    
    dependencies 
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
    


apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories 
    mavenCentral()
    mavenLocal()


sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies 
    compile("org.apache.commons:commons-lang3:3.4")

    compile("org.springframework.boot:spring-boot-starter-websocket")
    compile("org.springframework:spring-messaging")
    compile("org.springframework:spring-jdbc:4.2.1.RELEASE")

    compile("com.oracle:ojdbc7:7")

    compile('org.checkerframework:checker:1.9.5')
    compile('org.checkerframework:checker-qual:1.9.5')


task wrapper(type: Wrapper) 
    gradleVersion = '2.3'

运行 gradle bootRun 时出现以下错误:

2015-09-14 21:34:01.335  INFO 12324 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Users/xuegyu/Documents/Ecllipse/STARS/U2IDWebSocketDataServer/src/
main/resources, file:/C:/Users/xuegyu/Documents/Ecllipse/STARS/U2IDWebSocketDataServer/build/classes/main/, file:/C:/Users/xuegyu/Documents/Ecllipse/STARS/U2IDWebSocketDataServer/build/resources/main, file:/C:/Users/xuegy
u/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.4/5fe28b9518e58819180a43a850fbc0dd24b7c050/commons-lang3-3.4.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework.boot/s
pring-boot-starter-websocket/1.2.5.RELEASE/62a0af1bdd43c0bcce8ef0ef374f08a76c9cc881/spring-boot-starter-websocket-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-mess
aging/4.1.7.RELEASE/329df947037c2dff0a922a234de575cc0caca09d/spring-messaging-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/4.2.1.RELEASE/a30e0b1e2bce0928788ab
b42e8bae2eb71698aeb/spring-jdbc-4.2.1.RELEASE.jar, file:/C:/Users/xuegyu/.m2/repository/com/oracle/ojdbc7/7/ojdbc7-7.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker/1.9.5/197e8c6
c48ced1a8fbf64726c79fef13ddc945a6/checker-1.9.5.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.checkerframework/checker-qual/1.9.5/34a048e6cf641dbba241f66af48cf6de8c428329/checker-qual-1.9.5.jar, file:/
C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter/1.2.5.RELEASE/416b6339599892cb33077c9fd901de7669c38cbe/spring-boot-starter-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/c
aches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-web/1.2.5.RELEASE/afe2043ba5aa7d112a4ef0c907ebc6dbf8b93ce5/spring-boot-starter-web-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/f
iles-2.1/org.springframework/spring-websocket/4.1.7.RELEASE                                                                                                                                                                 /
e663637febcbd45e99d82a91fda0abb1d98e54b9/spring-websocket-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/4.1.7.RELEASE/8c6c02bcccfa23a74db59f7b7725e69e1af38f
04/spring-context-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-tx/4.2.1.RELEASE/f05b4465be1aab3493e83cb529f191cb7834b222/spring-tx-4.2.1.RELEASE.jar, file:/C:/User
s/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/1.2.5.RELEASE/d12969adffe18f6f778451b1a8d1dab485ab4a03/spring-boot-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2
.1/org.springframework.boot/spring-boot-autoconfigure/1.2.5.RELEASE/8f1ee1f5e37723dd0e2cd3b05c6fc9268798b93d/spring-boot-autoconfigure-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.spring
framework.boot/spring-boot-starter-logging/1.2.5.RELEASE/79df0d68a15dd5437010e46df1806482a7878e76/spring-boot-starter-logging-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/
1.14/c2df91929ed06a25001939929bff5120e0ea3fd4/snakeyaml-1.14.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-tomcat/1.2.5.RELEASE/9ac1752cd1a81b227d5f37e547077518
df15a624/spring-boot-starter-tomcat-1.2.5.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.4.6/3e63a25de4065697b185f523ed5e020c0db3ff0/jackson-databind-2.
4.6.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-validator/5.1.3.Final/334d46a93cf095160ce06d8382594b904933c808/hibernate-validator-5.1.3.Final.jar, file:/C:/Users/xuegyu/.gradle/c
aches/modules-2/files-2.1/org.springframework/spring-web/4.1.7.RELEASE/2d9245006b788d7d6afeec85a43e4bfe2e46340a/spring-web-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/sp
ring-webmvc/4.1.7.RELEASE/b6b9f604cb2223251cae67fff7ca2b1d                                                                                                                                                                  9
ff1c2d8/spring-webmvc-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-aop/4.1.7.RELEASE/127f005bac8ec1fbbbc5bb1595d78c6179394a46/spring-aop-4.1.7.RELEASE.jar, file:/C
:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/4.1.7.RELEASE/9bc3b81d05961f042ea4a45e84d60cdc59ea51f5/spring-expression-4.1.7.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modu
les-2/files-2.1/org.slf4j/jcl-over-slf4j/1.7.12/adef7a9e1263298255fdb5cb107ff171d07c82f3/jcl-over-slf4j-1.7.12.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.slf4j/jul-to-slf4j/1.7.12/8811e2e9ab9055e557
598dc9aedc64fd43e0ab20/jul-to-slf4j-1.7.12.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.slf4j/log4j-over-slf4j/1.7.12/d2444c9c7c1923304c25f86c5ee83a79a8166205/log4j-over-slf4j-1.7.12.jar, file:/C:/Use
rs/xuegyu/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.3/d90276fff414f06cb375f2057f6778cd63c6082f/logback-classic-1.1.3.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.apache.tom
cat.embed/tomcat-embed-core/8.0.23/79dc3aea4f447392ab0bdc1359c31a931cd307d6/tomcat-embed-core-8.0.23.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-el/8.0.23/5a1ca084156
665968232112b6606c0b259213aab/tomcat-embed-el-8.0.23.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-logging-juli/8.0.23/2ec89b09cb0eb133a03d9f513474f99ff667b93b/tomcat-e
mbed-logging-juli-8.0.23.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-websocket/8.0.23/839167a26dec5dcef85fb19e2e429878b7215293/tomcat-embed-websocket-8.0.23.jar, file
:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.4.0/d6a66c7a5f01cf500377bd669507a08cfeba882a/jackson-annotations-2.4.0.jar, file:/C:/Users/xuegyu/.gradle/caches/module
s-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.4.                                                                                                                                                                  6
/2a1f6edb86b8c6d29f37f6a807295d4e5c279707/jackson-core-2.4.6.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/javax.validation/validation-api/1.1.0.Final/8613ae82954779d518631e05daa73a6a954817d5/validation-ap
i-1.1.0.Final.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.jboss.logging/jboss-logging/3.1.3.GA/64499e907f19e5e1b3fdc02f81440c1832fe3545/jboss-logging-3.1.3.GA.jar, file:/C:/Users/xuegyu/.gradle/cache
s/modules-2/files-2.1/com.fasterxml/classmate/1.0.0/434efef28c81162b17c540e634cffa3bd9b09b4c/classmate-1.0.0.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/aopalliance/aopalliance/1.0/235ba8b489512805ac13a8
f9ea77a1ca5ebe3e8/aopalliance-1.0.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.12/8e20852d05222dc286bf1c71d78d0531e177c317/slf4j-api-1.7.12.jar, file:/C:/Users/xuegyu/.gradle/cache
s/modules-2/files-2.1/ch.qos.logback/logback-core/1.1.3/e3c02049f2dbbc764681b40094ecf0dcbc99b157/logback-core-1.1.3.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/4.2.1.RELE
ASE/6d39786b9f7b2a79897a0a83495f30002d9f8de3/spring-beans-4.2.1.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/4.2.1.RELEASE/97a7ff5ec8a070722d0809098a9964347130466c/
spring-core-4.2.1.RELEASE.jar, file:/C:/Users/xuegyu/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar]
Exception in thread "main" java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration#transactionManager due to internal clas
s not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)

第一行说应用程序无法从类路径开始,然后列出了那里几乎所有的依赖 jar。

有人遇到过这种情况吗?

【问题讨论】:

Tom,如果有帮助,我在调用依赖项时看到 this answer's syntax 与您的不同...不过我不熟悉 gradle。 【参考方案1】:

我解决了这个问题。

compile("org.springframework:spring-jdbc:4.2.1.RELEASE")

改成

compile("org.springframework:spring-jdbc")

【讨论】:

以上是关于gradle bootRun:应用程序无法使用类路径启动的主要内容,如果未能解决你的问题,请参考以下文章

BootRun 无法启动?

spring bootRun 和 Angular buildWatch 使用 Gradle

Gradle > 如何停止使用 gradle bootRun 启动的 Spring Boot 应用程序?

如何通过 gradle 任务使用 spring 配置文件运行 bootRun

使用 Spring Boot“bootRun”启动的应用程序在包含 Gradle Vaadin 插件时会导致 NoClassDefFoundError

并行启动多个 Gradle "spring-boot" 插件 "bootRun" 任务