如何通过Spring Boot禁用Tomcat清单扫描?

我们有一个依赖项(JAR),它确实包含一个清单文件,该清单文件在其Class-Path条目中引用了其他JAR

。应用程序不需要这些引用的其他JAR,因此不会将它们添加为依赖项。

当应用程序启动时,tomcat会尝试解析该类路径条目,并且最终在日志中出现很多错误。喜欢:

The Class-Path manifest attribute in /Users/me/.m2/repository/org/bytedeco/javacpp-presets/openblas/0.3.3-1.4.3/openblas-0.3.3-1.4.3.jar referenced one or more files that do not exist: file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/openblas/0.3.3-1.4.3/javacpp.jar

The Class-Path manifest attribute in /Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-platform-2019.0-1.4.3.jar referenced one or more files that do not exist: file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-linux-x86.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-linux-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-macosx-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-windows-x86.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-windows-x86_64.jar

The Class-Path manifest attribute in /Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl/2019.0-1.4.3/mkl-2019.0-1.4.3.jar referenced one or more files that do not exist: file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl/2019.0-1.4.3/javacpp.jar

The Class-Path manifest attribute in /Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-dnn-platform/0.16-1.4.3/mkl-dnn-platform-0.16-1.4.3.jar referenced one or more files that do not exist: file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-dnn-platform/0.16-1.4.3/mkl-dnn.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-dnn-platform/0.16-1.4.3/mkl-dnn-linux-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-dnn-platform/0.16-1.4.3/mkl-dnn-macosx-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-dnn-platform/0.16-1.4.3/mkl-dnn-windows-x86_64.jar

The Class-Path manifest attribute in /Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-platform-2019.0-1.4.3.jar referenced one or more files that do not exist: file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-linux-x86.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-linux-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-macosx-x86_64.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-windows-x86.jar,file:/Users/me/.m2/repository/org/bytedeco/javacpp-presets/mkl-platform/2019.0-1.4.3/mkl-windows-x86_64.jar

...

WARNING: Failed to scan [file:/Users/domi/.m2/repository/org/bytedeco/javacpp-presets/hdf5-platform/1.10.3-1.4.3/hdf5.jar] from classloader hierarchy

java.io.IOException: java.lang.reflect.InvocationTargetException

at org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:212)

at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65)

at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49)

at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:374)

at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:309)

...

Caused by: java.lang.reflect.InvocationTargetException

at java.base/jdk.internal.reflect.GeneratedConstructorAccessor78.newInstance(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

at org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:209)

... 49 more

Caused by: java.nio.file.NoSuchFileException: /Users/domi/.m2/repository/org/bytedeco/javacpp-presets/hdf5-platform/1.10.3-1.4.3/hdf5.jar

at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)

at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)

at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)

at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)

at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:145)

at java.base/java.nio.file.Files.readAttributes(Files.java:1763)

at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1222)

at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:726)

...

如此处所述,Tomcat已实施了一项开关以禁用清单扫描以防止出现此问题:https

:

//bz.apache.org/bugzilla/show_bug.cgi?id=59961

在常规的tomcat安装中,我们可以执行以下操作(https://tomcat.apache.org/tomcat-8.0-doc/config/jar-

scanner.html):

<Context>

...

<JarScanner scanManifest="false"/>

</Context>

如何通过Spring Boot" title="Spring Boot">Spring Boot禁用Tomcat清单扫描?

回答:

你可以喜欢底部

@Bean

public TomcatServletWebServerFactory tomcatFactory() {

return new TomcatServletWebServerFactory() {

@Override

protected void postProcessContext(Context context) {

((StandardJarScanner) context.getJarScanner()).setScanManifest(false);

}};

}

以上是 如何通过Spring Boot禁用Tomcat清单扫描? 的全部内容, 来源链接: utcz.com/qa/421789.html

回到顶部