Spring Boot常见问题(二)Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;

问题描述:通过Spring Boot官方提供的方式,写出如下HelloWorld代码。

@Controller
@EnableAutoConfiguration
public class HelloWorld {
    @RequestMapping("/wu")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloWorld.class, args);
    }
}

  在运行main()方法时,抛出如下异常。

org.springframework.context.ApplicationContextException: Unable to start embedded container;
   nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;)V
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at dolphin.springboot.controller.HelloWorld.main(HelloWorld.java:30) [classes/:na]
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;)V
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner$Tomcat8TldSkipSetter.setSkipPattern(SkipPatternJarScanner.java:106) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner.setPatternToTomcat8SkipFilter(SkipPatternJarScanner.java:61) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner.<init>(SkipPatternJarScanner.java:56) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.SkipPatternJarScanner.apply(SkipPatternJarScanner.java:87) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:209) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:178) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    ... 8 common frames omitted

  经检查,在org.apache.tomcat.util.scan.StandardJarScanner类中存在setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;)方法,并且亲自测试,可以正常使用。而抛出异常却说没有此方法。

分析原因:1.存在重复的jar包。2.版本调整带来的影响。

  经排查,发现MyEclipse Tomcat v7.0 Runtime Libraries包,和Maven Dependencies包中均包含org.apache.tomcat.util.scan.StandardJarScanner类。

  

  于是,取消MyEclipse Tomcat v7.0 Runtime Libraries包,运行正常。

  .   ____          _            __ _ _
 /\\ / ___‘_ __ _ _(_)_ __  __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ‘  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

2017-09-09 09:27:03.646  INFO 6400 --- [           main] d.springboot.controller.HelloWorld       : Starting HelloWorld on DESKTOP-N8HPR69 with PID 6400 (started by wushuai in C:\Users\wushuai\Workspaces\MyEclipse for Spring 2014\springboot Maven Webapp)
2017-09-09 09:27:03.648  INFO 6400 --- [           main] d.springboot.controller.HelloWorld       : No active profile set, falling back to default profiles: default
2017-09-09 09:27:03.679  INFO 6400 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]5680a576: startup date [Sat Sep 09 09:27:03 CST 2017]; root of context hierarchy
2017-09-09 09:27:04.734  INFO 6400 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-09-09 09:27:04.743  INFO 6400 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-09-09 09:27:04.744  INFO 6400 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-09-09 09:27:04.820  INFO 6400 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-09-09 09:27:04.820  INFO 6400 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1143 ms
2017-09-09 09:27:04.952  INFO 6400 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: ‘dispatcherServlet‘ to [/]
2017-09-09 09:27:04.956  INFO 6400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘characterEncodingFilter‘ to: [/*]
2017-09-09 09:27:04.956  INFO 6400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘hiddenHttpMethodFilter‘ to: [/*]
2017-09-09 09:27:04.956  INFO 6400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘httpPutFormContentFilter‘ to: [/*]
2017-09-09 09:27:04.956  INFO 6400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘requestContextFilter‘ to: [/*]
2017-09-09 09:27:05.266  INFO 6400 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.[email protected]: startup date [Sat Sep 09 09:27:03 CST 2017]; root of context hierarchy
2017-09-09 09:27:05.324  INFO 6400 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/wu]}" onto java.lang.String dolphin.springboot.controller.HelloWorld.home()
2017-09-09 09:27:05.327  INFO 6400 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-09-09 09:27:05.328  INFO 6400 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-09-09 09:27:05.356  INFO 6400 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-09 09:27:05.356  INFO 6400 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-09 09:27:05.398  INFO 6400 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-09-09 09:27:05.580  INFO 6400 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-09 09:27:05.650  INFO 6400 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-09-09 09:27:05.655  INFO 6400 --- [           main] d.springboot.controller.HelloWorld       : Started HelloWorld in 2.298 seconds (JVM running for 2.534)

解决办法:查看报错文件所在的包,移除重复部分。

时间: 2024-10-12 22:27:24

Spring Boot常见问题(二)Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.util.scan.StandardJarScanner.setJarScanFilter(Lorg/apache/tomcat/JarScanFilter;的相关文章

spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes

spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure

错误:org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWeb

详细错误: 1 org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedSer

spring boot配置spring-data-jpa的时候报错CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.NoSuchMethodError

F:\java\jdk8\jdk1.8.0_211\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\软件\IntelliJ IDEA 2019.2.2\lib\idea_rt.jar=7513:D:\软件\IntelliJ IDEA 2019.2.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\软件\IntelliJ IDEA 2019.2.2

spring quartz:Instantiation of bean failed; nested exception is java.lang.IncompatibleClassChangeErr

spring 调度类初始化失败,分析是jar包冲突,日志如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in file [D:\InstallApplication\apache-tomcat-7.0.23\wtpwebapps\campaign\WEB-INF\classes\spring\applicationConte

Spring出现Unexpected exception parsing XML document from class path resource [applicationBeans.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource异常

在自学Spring4的过程中,遇到了棘手的异常,一直找不到问题所在,后来经过对每个过程进行逐一排查之后,发现少了一个jar包:spring-aop-4.0.0.RELEASE.jar.完整的异常信息如下: Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from clas

spring报错 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [cn/itcast/b_anno/bean.xml]; nested exception is java.lang.

这次遇到的错是在 使用注解的方式 来使用事务的时候 在配置文件中配置了 但是却没有使用 补充:没有aop相关的包也会报这个错,需要加上aop的包 解决:在配置文件中将事务有关的配置移除了然后就好了          额,看来在配置文件中的东西一定注意啊,需要使用的时候才去进行配置,不要多配置也不要少配置

Failed to instantiate [引用 spring 配置文件的类]: Constructor threw exception; nested exception is java.lang.NullPointerException

本人的继承类引用了 service 层的方法,用的注解方式是@Autowired 该注解如果在容器 tomcat 启动后引用后不会报错,不会报 java.lang.NullPointerException 错误. 初始化时如果想调用数据库的数据,而此时 service 层的类没有实例化,导致 tomcat 启动时报空指针错误. 解决办法: @Componentpublic class MessageResource extends AbstractMessageSource implements

解决springboot启动失败问题:Unable to start embedded container;

全部报错内容如下: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalStateException: Expected method not found: java.lang.NoSuchMethodException: org.springframework.boot.context.e

【spring data jpa】启动报错:nested exception is java.util.NoSuchElementException

spring boot项目中 使用spring data jpa 启动报错: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dealerTransferServiceImpl': Unsatisfied dependency expressed through field 'dealerTransferDao'; nested exception i