AFTER upgrade from Spring boot 1.2 to 1.5.2, FileNotFoundException during Tomcat 8.5 Startup

后端 未结 3 1154
无人共我
无人共我 2020-12-03 04:46

I upgraded Spring Boot from 1.2.0 to 1.5.2.

After that upgrade, Tomcat 8.5 is th

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 05:20

    RootCause:

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

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

    From the javadoc of StandardJarScanner.

    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:

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

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

    • All of the extensions may be controlled via configuration.

    Solution1: Spring Boot specific.

    We can disable this jar scanning.

    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
    

    You can find similar properties from Tomcat here.

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

    Solution2: Spring specific

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

    Solution3 : Traditional Standalone Tomcat:

    
      ...
      
      ...
    
    

    Refer : The Jar Scanner Component.

提交回复
热议问题