禁用springboot内嵌tomcat的MANIFEST扫描
Posted 架构学习圈
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了禁用springboot内嵌tomcat的MANIFEST扫描相关的知识,希望对你有一定的参考价值。
本文介绍实现一个将word转为pdf的需求过程中,遇到jar扫描异常的问题排查及解决。本文采用springboot2.0集成jodconverter,使用openoffice6。
首先添加依赖,
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-spring-boot-starter</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.2.2</version>
</dependency>
修改[配置文件application.yml](https://github.com/sbraconnier/jodconverter/blob/master/jodconverter-samples/jodconverter-sample-spring-boot/src/main/resources/application.yml)
@Autowired private DocumentConverter converter;
格式转换:
converter.convert(new File(wordFilePath)).to(targetFile).as(DefaultDocumentFormatRegistry.html).execute();
[参考示例ConverterController.java](https://github.com/sbraconnier/jodconverter/blob/master/jodconverter-samples/jodconverter-sample-spring-boot/src/main/java/org/jodconverter/sample/springboot/ConverterController.java)
虽然能够正常转换成pdf文件,但是出现一些警告信息,终归不爽。提示信息如下:
08:52:43.929 WARN [-,,,] 11888 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/repository/org/openoffice/juh/4.1.2/ridl.jar] from classloader hierarchy
D:\repository\org\openoffice\juh\4.1.2\ridl.jar (系统找不到指定的文件。) :
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:197)
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:385)
at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:320)
at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:271)
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:234)
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
08:52:43.929 WARN [-,,,] 11888 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/repository/org/openoffice/juh/4.1.2/jurt.jar] from classloader hierarchy
D:\repository\org\openoffice\juh\4.1.2\jurt.jar (系统找不到指定的文件。) :
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:197)
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:385)
at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:320)
at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:271)
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:234)
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
08:52:43.930 WARN [-,,,] 11888 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/repository/org/openoffice/jurt/4.1.2/ridl.jar] from classloader hierarchy
D:\repository\org\openoffice\jurt\4.1.2\ridl.jar (系统找不到指定的文件。) :
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:197)
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:385)
at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:320)
at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:271)
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:234)
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
08:52:43.930 WARN [-,,,] 11888 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/D:/repository/org/openoffice/jurt/4.1.2/unoloader.jar] from classloader hierarchy
D:\repository\org\openoffice\jurt\4.1.2\unoloader.jar (系统找不到指定的文件。) :
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:225)
at java.util.zip.ZipFile.<init>(ZipFile.java:155)
at java.util.jar.JarFile.<init>(JarFile.java:166)
at java.util.jar.JarFile.<init>(JarFile.java:130)
at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:197)
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:385)
at org.apache.tomcat.util.scan.StandardJarScanner.processURLs(StandardJarScanner.java:320)
at org.apache.tomcat.util.scan.StandardJarScanner.doScanClassPath(StandardJarScanner.java:271)
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:234)
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262)
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104)
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
根据提示信息找到类StandardJarScanner,定位到
if (isScanManifest()) {
processManifest(jar, isWebapp, classPathUrlsToProcess);
}
打开文件juh-4.1.2.jar
\META-INF\MANIFEST.MF
Manifest-Version: 1.0
Class-Path: ridl.jar jurt.jar ../../lib/ ../bin/
Solar-Version: 412m3(Build:9782)
Sealed: true
RegistrationClassName: com.sun.star.comp.JavaUNOHelperServices
UNO-Type-Path:
果然是扫描并尝试加载了MANIFEST.MF的Class-Path。
isScanManifest()通过属性scanManifest来控制是否扫描Manifest。
设置禁用扫描清单文件,
Spring Boot 1.x:
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
return new TomcatEmbeddedServletContainerFactory() {
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
}
Spring Boot 2.0:
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
}
以上是关于禁用springboot内嵌tomcat的MANIFEST扫描的主要内容,如果未能解决你的问题,请参考以下文章
springBoot学习笔记内嵌tomcat和springmvc
springBoot学习笔记内嵌tomcat和springmvc