springboot启动嵌入式tomcat报错找不到jar包,关键字:FileNotFoundException,derbyLocale_cs.jar,StandardJarScanner.scan
异常:
java.io.FileNotFoundException: /Users/lanhuajian/.m2/repository/org/apache/derby/derby/10.13.1.1/derbyLocale_cs.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method) ~[?:1.8.0_152]
at java.util.zip.ZipFile.<init>(ZipFile.java:225) ~[?:1.8.0_152]
at java.util.zip.ZipFile.<init>(ZipFile.java:155) ~[?:1.8.0_152]
at java.util.jar.JarFile.<init>(JarFile.java:166) ~[?:1.8.0_152]
at java.util.jar.JarFile.<init>(JarFile.java:130) ~[?:1.8.0_152]
at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.23.jar:?]
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.23.jar:?]
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.23.jar:?]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [?:1.8.0_152]
at java.util.concurrent.FutureTask.run(FutureTask.java) [?:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
springboot集成hadoop等组件后会报这个错,一般和hadoop集成需要把老版本的sevlet、jsp、tomcat依赖去掉,但是我去掉之后还是存在。
所以我跟踪了springboot初始化tomcat的代码,发现在TomcatEmbeddedServletContainerFactory#prepareContext()
有个tldSkipPatterns
的东西, 就心想这个是不是会告诉tomcat不要扫描这些jar包呢?试了一下,真的可以!
因此可以得出如下解决方案,在初始化TomcatEmbeddedServletContainerFactory
后,在后置bean处理器中给它加上tldSkipPatterns即可
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
@Configuration
public class TomcatContainerConfig {
@Value("${tldSkipPatterns}")
private String[] tldSkipPatterns;
@Bean
public BeanPostProcessor TomcatContainerPostProcessor() {
List<String> notEmptyTldSkipPatterns = Arrays.stream(tldSkipPatterns)
.filter(tldSkipPattern -> !tldSkipPattern.trim().isEmpty())
.collect(toList());
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals("tomcatEmbeddedServletContainerFactory") &&
bean instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) bean;
if (!notEmptyTldSkipPatterns.isEmpty()) {
factory.addTldSkipPatterns(notEmptyTldSkipPatterns.toArray(new String[0]));
}
}
return bean;
}
};
};
}
增加下面的配置到 application.properties
:
tldSkipPatterns=derbyLocale_*.jar,jaxb-api.jar,jsr173_1.0_api.jar,jaxb1-impl.jar,activation.jar
springboot启动嵌入式tomcat报错找不到jar包,关键字:FileNotFoundException,derbyLocale_cs.jar,StandardJarScanner.scan的更多相关文章
- springboot 启动的时候报错 Error creating bean with name 'solrClient'
springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...
- eclipse使用maven,启动工程tomcat报错:java.lang.ClassNotFoundException: org.springframework.web.context.Contex
maven是个不错的管理jar包工具,但是我们在eclipse使用maven时,总是遇上这样那样的问题,比如今天,我编译工程,启动过后,tomcat报错:java.lang.ClassNotFound ...
- SpringBoot启动嵌入式tomcat源码解读
一.SpringBoot自动拉起Tomcat SpringBoot框架是当前比较流行的java后端开发框架,与maven结合大大简化了开发人员项目搭建的步骤,我们知道SpringBoot的启动类启动后 ...
- web项目——启动时tomcat报错:Server Tomcat v7.0 Server at localhost failed to start.
报错信息:Server Tomcat v7.0 Server at localhost failed to start. 报错截图: 原因分析:在使用SSM框架时,生成的mapping与系统配置文件不 ...
- eclipse debug启动时tomcat报错
Class.getDeclaredConstructors0(boolean) line: not available [native method] tomcat debug启动突然启动不起来 停 ...
- 三、SpringBoot启动时JDBC报错:You must configure either the server or JDBC driver (via the serverTimezone configuration property)
错误提示: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connectio ...
- tomcat 报错处理
一.tomcat报错找不到资源集市 原因:tomcat的配置文件sever.xml 里的 docbase配置被Eclispe修改了 解决方法:修改回来 <Context docBase=&quo ...
- IDEA启动Tomcat报错
Maven编译成功, 可是启动Tomcat报错: Application Server was not connected before run configuration stop, reason: ...
- maven 项目启动tomcat报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
maven项目启动tomcat报错: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...
随机推荐
- ie版本
<!--[if lte IE 6]> 自定义代码 <![endif]-->
- nodejs-配置vs code的插件
在windows上安装好npm后,再在终端里使用npm安装express,再安装express-generator 进入express的目录, 在终端中执行 npm install 启动expres ...
- 组件的使用(三)AutoCompleteTextView的使用
AutoCompleteTextView经常使用的属性: android:completionHint 下拉列表以下的说明性文字 android:completionThreshold 弹出下来列表的 ...
- HDU 5167
范围 内的斐波那契的数不多,求出范围内的数,再暴力枚举即可. #include <iostream> #include <cstdio> #include <algori ...
- HDU 4340
好题一道啦.做这题时,抓住两个问题:一.给某点染色时,其连通的点是否已有一点以全部代价染色.二.该点染什么颜色. 嗯.第二个问题很容易,但第一个问题不容易了.我一开始就考虑祖父子三层结点的关系,认为在 ...
- js面向对象编程:怎样实现方法重载
js中怎样实现方法重载?这涉及到三个问题 1同名函数的调用问题 2函数中特殊的參数arguments 3怎样利用arguments实现方法重载 1同名函数的调用问题 都知道在js中假设存在多个名称同样 ...
- DBS-Oracle:表的连接查询
ylbtech-DBS-Oracle:表的连接查询 链接查询是指基于两个或两个以上表或试图的查询.在实际应用中,查询单个表可能无法满足应用程序的实际需求(例如显示雇员的部门名称以及雇员名),在这种情况 ...
- iris中间件
最近使用golang写的时候涉及到权限校验,用中间件(使用iris框架内的东西) 自己摸索出一种自己的方式 iris.UseFunc(MiddlewareFunc)使用这个方法,会在所有的请求之前执行 ...
- linux中openssl生成证书和自签证书
1.首先要生成服务器端的私钥(key文件): 命令: openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加密key文件(参数des3便 ...
- Vue 菜单栏点击实现高亮显示
步骤: 遍历对象(goods)获取菜单栏每一项的对象(item)和下标(index) 添加点击事件toggle(),传入下标参数:@click="fn1();fn2()" 动态切换 ...