gpt4 book ai didi

java - Spring Boot Embedded Tomcat 依赖在启动时抛出异常

转载 作者:搜寻专家 更新时间:2023-11-01 03:32:55 34 4
gpt4 key购买 nike

我正在从 JBoss/Wildfly 移植一个旧应用程序以在 tomcat 上运行。大多数我能够使用网络上的资源完成的事情。但是,我对最新一期的运气不太好。我很早就知道我必须添加

providedRuntime('org.apache.tomcat.embed:tomcat-embed-jasper')

作为请求路由的依赖。如果我不包含这个依赖,我在发出请求时会得到 404 错误。现在,这似乎对我的应用程序没有任何不利影响,但如果没有任何问题,我不希望出现启动错误。

它的目标环境是运行 Tomcat 8 的 AWS,它在部署时工作得很好。我只在本地运行时看到此错误(已启用 DEBUG):

2017-04-10 09:40:26.957 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner  : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/org.apache.velocity/velocity/1.6.2/1b470ec12a9b8aa69b0458a7e477dacb2cbdd6a0/velocity-1.6.2.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/net.minidev/accessors-smart/1.1/a527213f2fea112a04c9bdf0ec0264e34104cd08/accessors-smart-1.1.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/c9ad4a0850ab676c5c64461a05ca524cdfff59f1/json-simple-1.1.1.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.1/87c0ea803b69252868d09308b4618f766f135a96/objenesis-2.1.jar] from classpath
2017-04-10 09:40:26.959 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-api.jar] from classpath
2017-04-10 09:40:26.963 WARN 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-api.jar] from classloader hierarchy

java.io.FileNotFoundException: /Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-api.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_121]
at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_121]
at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_121]
at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_121]
at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_121]
at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:48) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.11.jar:8.5.11]
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.11.jar:8.5.11]
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.11.jar:8.5.11]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.11.jar:8.5.11]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.11.jar:8.5.11]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]

java.io.FileNotFoundException: /Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/2.2.11/a49ce57aee680f9435f49ba6ef427d38c93247a6/jaxb-core.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_121]
at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_121]
at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_121]
at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_121]
at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_121]

问题是,依赖项解析失败,因为没有版本附加到扫描的 JAR 路径。这是我丢失文件的本地存储库:

bhodgson-mbp:a49ce57aee680f9435f49ba6ef427d38c93247a6 bhodgson$ pwd
/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/2.2.11/a49ce57aee680f9435f49ba6ef427d38c93247a6
bhodgson-mbp:a49ce57aee680f9435f49ba6ef427d38c93247a6 bhodgson$ ls -lt
total 2048
-rw-r--r-- 1 bhodgson staff 1047863 Apr 10 08:44 jaxb-impl-2.2.11.jar

这只发生在 jaxb-impl 和 jaxb-core 上

我已经尝试清理依赖冲突,但除了将一个旧版本的 jaxb-impl 作为瞬时依赖之外,没有发现任何其他东西。

那我该怎么办呢?我看到所有依赖项都从 gradle 缓存中解析,但不明白为什么请求的依赖项没有解析为正确的版本。我猜是因为这通常包含在 JRE/JDK 或 Tomcat 本身中。

这是我的 gradle 文件:

buildscript {
ext {
springBootVersion = '1.5.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

war {
archiveName = "ROOT.war"
destinationDir = new File("${rootDir}/runway/FS_ROOT/opt/tomcat/webapps/")
}

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

configurations {
providedRuntime
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework:spring-oxm:4.3.5.RELEASE')
compile('org.springframework.webflow:spring-webflow:2.4.4.RELEASE')
compile('org.springframework.security:spring-security-taglibs')

compile('commons-lang:commons-lang:2.6')
compile('commons-io:commons-io:2.1')
compile('commons-logging:commons-logging:1.2')
compile('commons-digester:commons-digester:2.1')
compile('commons-beanutils:commons-beanutils:1.9.3')
compile('commons-fileupload:commons-fileupload:1.2.2')
compile('commons-codec:commons-codec:1.8')

compile('joda-time:joda-time:2.1')

compile('com.jcraft:jsch:0.1.42')

compile('org.codehaus.jackson:jackson-mapper-asl:1.9.5')

compile('com.sun.jersey:jersey-client:1.19.3')
compile('com.sun.jersey.contribs:jersey-spring:1.19.3')
compile('com.sun.jersey:jersey-json:1.19.3'){
exclude module: 'jaxb-impl'
}

compile('javax.servlet:javax.servlet-api:3.1.0')
compile('javax.servlet.jsp:jsp-api:2.2')

compile('org.apache.cxf:cxf-rt-frontend-jaxws:3.1.6')
compile('org.apache.cxf:cxf-rt-transports-http:3.1.6')
compile('org.apache.tiles:tiles-core:3.0.7')
compile('org.apache.tiles:tiles-extras:3.0.7')
compile('org.apache.tiles:tiles-servlet:3.0.7')
compile('org.apache.tiles:tiles-jsp:3.0.7')
compile('org.apache.tiles:tiles-api:3.0.7')
compile('org.apache.tiles:tiles-template:3.0.7')

compile('com.github.dandelion:datatables-jsp:1.1.0')
compile('com.github.dandelion:datatables-compression-yui:0.9.3')
compile('com.github.dandelion:datatables-servlet2:0.9.3')

compile('com.sun.xml.bind:jaxb-core:2.2.11')
compile('com.sun.xml.bind:jaxb-impl:2.2.11')

testCompile('org.testng:testng:6.3.1')
testCompile('org.easymock:easymock:3.1')
testCompile('org.springframework.boot:spring-boot-starter-test')

providedRuntime('javax.servlet:jstl')
providedRuntime('org.apache.tomcat.embed:tomcat-embed-jasper')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
}

最佳答案

我遇到了同样的问题并做了一些研究。

问题是在 jars 中搜索 tld 文件的 tomcat TldScanner。它使用 StandardJarScanner 并根据 Tomcat Issue 59226递归搜索在 Class-Path header 下的 jar list 中定义的 jar .

为了构造在 list 中找到的依赖项的路径,它将依赖项名称附加到源 jar 路径。它适用于同一目录中的 jar,例如 exploded war 中的 lib 目录或 tomcat lib 目录,但在从 .m2 或 .gradle 缓存构造类路径的情况下失败:

路径来自

/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-core.jar

与 list 中的 jaxb-api.jar 连接,结果路径无效

/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-api.jar

例如,当您从 IDE 启动应用程序时可能会发生这种情况。

此处说明如何禁用 JarScanner 的 list 扫描或过滤掉您确定不包含 tld 文件的 jar:https://stackoverflow.com/a/43280452/5190486

此答案还包含有关 Tomcat JarScanner 问题的信息:https://stackoverflow.com/a/43002625/5190486

关于java - Spring Boot Embedded Tomcat 依赖在启动时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43328022/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com