Disable scanManifest of Jar Scan in tomcat embed in spring boot
Asked Answered
S

4

16

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.

Smaragdine answered 12/4, 2017 at 13:23 Comment(0)
A
17

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

Asarum answered 7/11, 2018 at 18:10 Comment(7)
Setting this will break .JSP support as no TLDs will be resolved at all.Thermophone
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-*.jarAsarum
How about if I want multiple patterns? This sort of thing works: server.tomcat.additional-tld-skip-patterns=jaxb-api*.jar,txw2*Maiolica
Actually this solution turns off scanning for TLD so if you have tag library in the jar it will not be included in your runtimeAswan
@JJRoman what's your alternative solution if i keep TLD scannig for tag library?Zymogen
@Zymogen actually one above from rustyx worked for meAswan
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...Zymogen
D
12

Edit: how about this?

  @Bean
  public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
      @Override
      protected void postProcessContext(Context context) {
        ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
      }
    };
  }
Dissension answered 4/8, 2017 at 8:0 Comment(3)
Thank you! I have added this line to my Application Class and the warning was gone.Surplice
I get this error Unable to start EmbeddedWebApplicationContext due to multiple EmbeddedServletContainerFactory beans : tomcatFactory,embeddedServletContainerFactory. How can I solve it?Recrudesce
see rustyx answer for Spring Boot 2.XMarquez
T
11

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.

Thermophone answered 7/9, 2018 at 20:21 Comment(0)
A
0

Slight variation to that suggested by rustyx, based on this, required as I was customising my actuator management port.

@Bean
public TomcatServletWebServerFactory containerFactory() {
    return new CustomTomcatServletWebServerFactory();
}

static final class CustomTomcatServletWebServerFactory
    extends TomcatServletWebServerFactory {

    @Override
    protected void postProcessContext(Context context) {
        ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
    }

}
Appall answered 6/1, 2022 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.