gpt4 book ai didi

spring-boot - 如何使用 spring boot 禁用 tomcat list 扫描?

转载 作者:行者123 更新时间:2023-11-28 22:39:17 25 4
gpt4 key购买 nike

我们有一个依赖项 (JAR),它在它的 Class-Path 条目中包含一个引用其他 JAR 的 list 文件。这些引用的其他 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 实现了一个开关来禁用 list 扫描以防止出现此问题: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 禁用 tomcat list 扫描?

最佳答案

你可以在底部点赞

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

关于spring-boot - 如何使用 spring boot 禁用 tomcat list 扫描?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55481466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com