从 Spring boot 1.2 升级到 1.5.2 后,Tomcat 8.5 启动期间出现 FileNotFoundException [英] AFTER upgrade from Spring boot 1.2 to 1.5.2, FileNotFoundException during Tomcat 8.5 Startup

查看:30
本文介绍了从 Spring boot 1.2 升级到 1.5.2 后,Tomcat 8.5 启动期间出现 FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级 Spring 启动从 1.2.0 到 1.5.2.

I upgraded Spring Boot from 1.2.0 to 1.5.2.

升级后,Tomcat 8.5启动期间抛出FileNotFoundException.

After that upgrade, Tomcat 8.5 is throwing FileNotFoundException during startup.

下面是其中一个异常,它抛出超过大约 10 个类似的异常.

Below is one of those exceptions, It is throwing more than ~10 similar exceptions.

我不知道这些 jars 的目的,换句话说,我没有在 pom.xml 中为这些 jars 添加 xml.

I have no idea about the purpose of these jars, In other words, I didn't add <dependency> for these jars in pom.xml.

INFO: Starting Servlet Engine: Apache Tomcat/8.5.11
Apr 06, 2017 3:53:57 PM org.apache.tomcat.util.scan.StandardJarScanner scan
WARNING: Failed to scan [file:/C:/Users/myname/.m2/repository/com/sun/xml/ws/jaxws-rt/2.1.7/jaxws-api.jar] from classloader hierarchy
java.io.FileNotFoundException: C:Usersmyname.m2
epositorycomsunxmlwsjaxws-rt2.1.7jaxws-api.jar (The system cannot find the file specified)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:219)
    at java.util.zip.ZipFile.<init>(ZipFile.java:149)
    at java.util.jar.JarFile.<init>(JarFile.java:166)
    at java.util.jar.JarFile.<init>(JarFile.java:130)
    at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60)
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:48)
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338)
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288)
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104)
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

任何帮助将不胜感激.

推荐答案

RootCause:

根据 Tomcat Wiki,Servlet 3.0 规范需要服务器启动期间的 Jar 扫描.

As per Tomcat Wiki, Servlet 3.0 specification requires Jar scanning during server startup.

Tomcat 正在使用 org.apache.tomcat.util.scan.StandardJarScanner 用于此目的.

Tomcat is using org.apache.tomcat.util.scan.StandardJarScanner for this purpose.

来自 StandardJarScanner 的 javadoc.

From the javadoc of StandardJarScanner.

默认的 JarScanner 实现扫描 WEB-INF/lib 目录其次是提供的类加载器,然后处理类加载器等级制度.这个实现足以满足要求Servlet 3.0 规范,并提供了许多Tomcat 特定的扩展.扩展名是:

The default JarScanner implementation scans the WEB-INF/lib directory followed by the provided classloader and then works up the classloader hierarchy. This implementation is sufficient to meet the requirements of the Servlet 3.0 specification as well as to provide a number of Tomcat specific extensions. The extensions are:

  • 扫描类加载器层次结构(默认启用)测试所有文件以查看它们是否为 JAR(默认禁用)

  • Scanning the classloader hierarchy (enabled by default) Testing all files to see if they are JARs (disabled by default)

测试所有目录以查看它们是否是分解的 JAR(默认禁用)

Testing all directories to see if they are exploded JARs (disabled by default)

所有扩展都可以通过配置进行控制.

解决方案 1:特定于 Spring Boot.

我们可以禁用这个jar扫描.

We can disable this jar scanning.

我通过在 application-xxx.properties 文件中添加以下属性来禁用它.此属性是 Spring Boot 特定的.

I disabled it by adding below property in application-xxx.properties file. This property is Spring Boot specific.

# Comma-separated list of additional patterns that match jars to ignore for TLD scanning.    
server.tomcat.additional-tld-skip-patterns=*.jar

您可以在 Tomcat 中找到类似的属性 这里.

You can find similar properties from Tomcat here.

这些属性可用于配置传统 tomcat(-spring boot)应用程序.

These properties can be used to configure traditional tomcat (non-spring boot) applications.

解决方案 2:特定于 Spring 的

您可以为 ma​​nifest 文件禁用 JarScanner,如下所示.

You can disable the JarScanner for manifest files as below.

@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
  return new TomcatEmbeddedServletContainerFactory() {
    @Override
    protected void postProcessContext(Context context) {
      ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
    }
  };
}

解决方案 3:传统的独立 Tomcat:

<Context>
  ...
  <JarScanner scanManifest="false"/>
  ...
</Context>

参考:Jar 扫描器组件.

这篇关于从 Spring boot 1.2 升级到 1.5.2 后,Tomcat 8.5 启动期间出现 FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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