12

I'm getting some warnings in log, like this:

java.io.FileNotFoundException: C:\Users\user\.m2\repository\com\lowagie\itext\2.0.8\bcmail-jdk14-138.jar (O sistema não pode encontrar o arquivo especificado)
    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.6.jar:8.5.6]
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:48) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.6.jar:8.5.6]
    at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.6.jar:8.5.6]
    at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) [tomcat-embed-core-8.5.6.jar:8.5.6]
    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]

In a standalone tomcat I can create a context.xml with:

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

How can I disable the JarScanner for manifest files (https://tomcat.apache.org/tomcat-8.0-doc/config/jar-scanner.html) in a java configuration class using Spring Boot.

Clifford
  • 76,825
  • 12
  • 79
  • 145
Beto Neto
  • 3,267
  • 3
  • 38
  • 70

3 Answers3

10

Edit: how about this?

  @Bean
  public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
      @Override
      protected void postProcessContext(Context context) {
        ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
      }
    };
  }
Oleg Tsernetsov
  • 101
  • 1
  • 4
  • Thank you! I have added this line to my Application Class and the warning was gone. – Marcel Zebrowski Mar 15 '18 at 13:13
  • I get this error `Unable to start EmbeddedWebApplicationContext due to multiple EmbeddedServletContainerFactory beans : tomcatFactory,embeddedServletContainerFactory`. How can I solve it? – wonsuc Dec 28 '20 at 03:29
7

Just trying to improve Oleg's excellent answer about Spring Boot 1.x..

Here's the corresponding code for Spring Boot 2.0 (Tomcat 8.5):

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

Just add that to your application's configuration.

rustyx
  • 62,971
  • 18
  • 151
  • 210
6

This is controllable via a property now:

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

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

checketts
  • 11,619
  • 10
  • 44
  • 68
  • 1
    Setting this will break .JSP support as no TLDs will be resolved at all. – rustyx Mar 11 '19 at 15:17
  • 4
    This doesn't break .JSP support. It disables using manifest files to configure additional scanning. You would replace the `*.jar` pattern with the one causing you troubles. For example in my project I use `server.tomcat.additional-tld-skip-patterns: jaxb-*.jar` – checketts Mar 12 '19 at 17:42
  • How about if I want multiple patterns? This sort of thing works: server.tomcat.additional-tld-skip-patterns=jaxb-api*.jar,txw2* – Joey Oct 10 '19 at 22:51
  • 1
    Actually this solution turns off scanning for TLD so if you have tag library in the jar it will not be included in your runtime – JJ Roman Apr 14 '20 at 13:06
  • @JJRoman what's your alternative solution if i keep TLD scannig for tag library? – Aerox May 29 '20 at 16:23
  • @Aerox actually one above from rustyx worked for me – JJ Roman Jun 08 '20 at 21:27
  • Yes, I mean...if you put "false", you always skip every jar, but what if someone want to skip some specific ones? Or maybe the solution is to put the jar at compile time in case you don't need to request it at runtime? maybe that's what is confusing me... – Aerox Jun 24 '20 at 19:44