Spring Boot嵌入式Tomcat依赖项在启动时引发异常 [英] Spring Boot Embedded Tomcat Dependency Throws Exception On Startup

查看:668
本文介绍了Spring Boot嵌入式Tomcat依赖项在启动时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从JBoss/Wildfly移植一个旧的应用程序以在tomcat上运行.我可以使用网络上的资源完成的大多数工作.但是,我对最新一期不太满意.我很早就知道我必须添加

I'm porting an old application from JBoss/Wildfly to run on tomcat. Most everything I've been able to accomplish with the resources found on the web. However, I am not having much luck with the latest issue. I learned early on that I had to add

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

作为请求路由的依赖项.如果不包括此依赖项,则发出请求时会出现404错误.现在,这似乎对我的应用程序没有任何不利影响,但是如果没有错误,我将不理解启动错误.

as a dependency for request routing. If I don't include this dependency, I will get 404 errors when making a request. Now, this doesn't appear to have any adverse effect on my application, but I don't appreciate startup errors if nothing is wrong.

此目标环境是运行Tomcat 8的AWS,部署后运行良好.我只看到此错误在本地运行(启用了调试):

The target environment for this is AWS running Tomcat 8 and it works just fine when deployed. I only ever see this error running locally (DEBUG enabled):

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路径的版本.这是丢失文件的本地存储库:

The problem is, the dependency resolution fails because there is no version attached to the JAR path that is scanned. Here is my local repo for the missing file(s):

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

This happens for only jaxb-impl and jaxb-core

我曾尝试清理依赖冲突,但除了临时版本的jaxb-impl以外,没有找到其他任何东西.

I've tried cleaning up dependency collisions but didn't find anything other than one older version of jaxb-impl as a transient dependency.

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

So what can I do? I see that all dependencies are being resolved from a gradle cache, but don't understand why the requested dependency isn't resolving to a correct version. I'm going to guess because this is typically included with either the JRE/JDK or Tomcat itself.

这是我的gradle文件:

Here is my gradle file:

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')
}

推荐答案

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

I faced with same problem and did some research.

问题是要在jar中搜索tld文件的tomcat TldScanner.它使用StandardJarScanner并根据 Tomcat问题59226 递归搜索jar中定义的jar清单在类路径标头下.

The problem is tomcat TldScanner that searches tld files in jars. It uses StandardJarScanner and according Tomcat Issue 59226 recursively searches jars defined in jar manifest under Class-Path header.

要构造清单中找到的依赖项的路径,它会将依赖项名称附加到源jar路径中.它适用于同一目录中的jar,例如爆炸战争中的lib目录或tomcat lib目录中的jar,但在从.m2或.gradle缓存构造的类路径的情况下会失败:

To construct path to dependency found in manifest it appends dependency name to source jar path. It works well for jars in same directory such as lib directory in exploded war or tomcat lib directory, but fail in such cases where classpath constructed from .m2 or .gradle cache:

来自

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

与清单中的jaxb-api.jar串联,并且生成的路径无效

concatenated with jaxb-api.jar from manifest and resulting path is invalid

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

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

For example it could happen when you start application from IDE.

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

Here instructions how to disable manifest scan for JarScanner or filter out jars that you sure not contain tld files: https://stackoverflow.com/a/43280452/5190486

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

Also this answer contains information about Tomcat JarScanner issues: https://stackoverflow.com/a/43002625/5190486

这篇关于Spring Boot嵌入式Tomcat依赖项在启动时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆