java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean

java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean

java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean

把pom.xml 中的spring-boot-starter-parent的version由1.3.5.RELEASE改为现在的1.5.6.RELEASE,再次运行

<parent>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-starter-parent</artifactId>
                            <version>1.5.6.RELEASE</version>
                   <relativePath/> <!-- lookup parent from repository -->
         </parent>

报错如下:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.baiwang.registry.RegistryApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:519) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:278) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:168) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.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 com.baiwang.registry.RegistryApplication.main(RegistryApplication.java:15) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:232) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:510) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 17 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_131]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_131]
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
... 24 common frames omitted

 

原因分析:找不org.springframework.boot.context.embedded.FilterRegistrationBean,查看源码发现:在1.5.6版本中FilterRegistrationBean的包路径已经改为org.springframework.boot.web.servlet.org.springframework.boot.web.servlet.FilterRegistrationBean,所以引发错误。

解决办法:既然是引用了以前的包路径,说明是pom.xml文件的问题。检查发现spring-cloud-dependencies 的版本没有更新,改为Dalston.SR3解决问题。

<dependencyManagement>

              <dependencies>

                     <dependency>

                            <groupId>org.springframework.cloud</groupId>

                            <artifactId>spring-cloud-dependencies</artifactId>
   <version>Dalston.SR3</version>

                            <type>pom</type>

                            <scope>import</scope>

                     </dependency>

              </dependencies>

       </dependencyManagement>

 

posted @ 2018-11-30 14:39 路迢迢 阅读( ...) 评论( ...) 编辑 收藏
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402) at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) at com.rwa.AdminApplication.main(AdminApplication.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
最新发布
06-03
<think>好的,我现在需要帮助用户解决Spring Boot应用中嵌入式Tomcat无法启动的问题。用户已经提供了之前的对话和一些引用内容,我需要结合这些信息来生成有效的解决方案。首先,回顾用户的问题,用户遇到了“Unableto startembedded Tomcat”的错误,导致Web服务器无法启动。之前的回答已经列出了一些可能的原因,比如端口冲突、静态资源路径问题、Servlet组件初始化失败、数据库连接池配置错误、依赖冲突、Spring Security配置问题等。现在用户再次提问,可能需要更详细或更针对性的解决方案,或者之前的问题仍未解决。接下来,我需要查看用户提供的引用内容。引用[1]提到Spring Boot对嵌入式Tomcat的WebSocket自动配置,引用[2]显示应用名和环境为unknown,可能涉及配置问题,引用[3]涉及Activiti的升级说明和脚本任务配置,引用[4]是一个定时任务的代码示例。这些引用中,引用[2]可能与应用配置相关,比如应用名未正确设置导致服务发现失败,或者某些插件路径配置不正确。引用[3]提到的脚本任务可能影响Tomcat启动,如果存在旧版配置或JDK兼容性问题。但用户当前的问题是关于Tomcat启动,所以需要优先考虑常见的启动问题。用户当前的提问是希望解决嵌入式Tomcat无法启动的问题,需要结合之前的回答和新的引用内容。可能用户的问题还没有完全解决,或者需要更深入的分析步骤。首先,我应该检查常见的启动问题,如端口冲突、依赖冲突、配置错误等。然后,结合用户提供的引用,特别是引用[2]中的配置信息,可能存在HTTP入口模式或Java子调用行为的配置错误,导致Tomcat初始化失败。例如,插件路径为null或某些模式匹配不正确,可能引发异常。另外,引用[2]中的"exceptionThreshold"和"sampleRate"可能涉及监控或日志配置,如果这些配置错误,可能在应用启动时抛出异常,导致Tomcat无法启动。需要检查这些配置项是否正确,或者是否有相关的日志输出。 引用[3]提到的脚本任务自动存储变量的问题,可能与JDK版本不兼容有关。如果用户的项目中使用了Activiti或类似的库,并且配置了脚本任务,可能需要检查JDK版本是否符合要求,或者是否有相关的配置错误导致Tomcat启动时初始化失败。 引用[4]中的定时任务代码可能没有问题,但如果定时任务中引用了未正确初始化的Bean(如messagingTemplate),可能在应用启动时导致上下文加载失败,从而Tomcat无法启动。需要检查是否有循环依赖或Bean初始化顺序的问题。 接下来,我需要将这些可能性整理成结构化的解决方案,分步骤帮助用户排查问题。同时,需要结合之前的回答,补充可能遗漏的点,比如检查应用名称配置、插件路径、脚本任务配置、定时任务中的Bean注入问题等。此外,用户提供的引用[2]中的配置可能属于某个特定的监控或APM工具,比如SkyWalking或Pinpoint,这些工具的插件配置错误可能导致类加载问题或资源冲突,从而阻止Tomcat启动。需要检查相关插件的配置是否正确,或者暂时禁用这些插件以排除问题。 最后,需要确保解决方案的步骤清晰,包括检查日志、验证配置、排除依赖冲突、检查Bean初始化等,并引用相关的引用内容作为支持。同时,生成的相关问题需要与当前问题紧密相关,帮助用户进一步排查可能的原因。</think>### Spring Boot嵌入式Tomcat无法启动的解决方案 以下是针对`Unable to start embedded Tomcat`问题的详细排查步骤和解决方案,结合引用内容和常见原因: --- #### 1. **检查端口冲突** **问题现象**:日志中可能包含`Port already in use`错误。 **解决方案**: - 修改`application.properties`或`application.yml`中的端口号: ```yaml server: port: 8081 # 尝试未被占用的端口 ``` - 使用命令行工具查找占用端口的进程: ```bash lsof -i :8080 # Linux/Mac netstat -ano | findstr :8080 # Windows ``` --- #### 2. **排查依赖冲突** **问题现象**:启动时抛出`ClassNotFoundException`或`NoSuchMethodError`。 **解决方案**: - 通过Maven命令生成依赖树: ```bash mvn dependency:tree -Dincludes=org.apache.tomcat # 检查Tomcat依赖版本 ``` - 确保Spring Boot版本与Tomcat依赖兼容(例如Spring Boot 2.x默认使用Tomcat 9,避免手动引入冲突版本)[^1]。 --- #### 3. **验证静态资源配置** **问题现象**:资源路径错误导致`404`或`ServletContext`初始化失败。 **解决方案**: - 检查静态资源路径配置(如`resources/static`或自定义路径): ```java @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("classpath:/static/"); } } ``` - 确保`@EnableWebMvc`未覆盖默认配置[^1]。 --- #### 4. **分析插件或中间件配置** **问题现象**:引用[2]中的配置可能涉及APM工具(如SkyWalking)或自定义插件,错误配置导致类加载失败。 **解决方案**: - 检查`pluginsPath`是否指向有效目录,或暂时禁用插件测试: ```json { "pluginsPath": "/valid/path", // 修正为实际路径 "pluginIdentities": [] // 临时清空插件列表 } ``` - 确保`httpEntrancePatterns`和`javaSubInvokeBehaviors`中的正则表达式匹配有效接口[^2]。 --- #### 5. **检查脚本任务配置** **问题现象**:引用[3]提到旧版JDK脚本引擎兼容性问题,可能导致`ServletContainerInitializer`初始化失败。 **解决方案**: - 若项目使用Activiti等流程引擎,检查`scriptTask`配置: ```xml <scriptTask scriptFormat="javascript" autoStoreVariables="false" /> ``` - 升级JDK或改用Nashorn引擎(JDK 8)或GraalVM(JDK 11+)[^3]。 --- #### 6. **验证数据库连接池** **问题现象**:数据库连接超时或驱动类未找到。 **解决方案**: - 检查`application.yml`中的数据库配置: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/mydb?useSSL=false username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver # 确保驱动类存在 ``` - 添加连接池健康检查: ```java @Bean public DataSource dataSource() { HikariDataSource dataSource = new HikariDataSource(); dataSource.setConnectionTestQuery("SELECT 1"); return dataSource; } ``` --- #### 7. **查看完整错误日志** **关键步骤**: - 启用调试日志以捕获详细错误: ```properties logging.level.root=DEBUG ``` - 关注以下日志片段: - `WebServerApplicationContext`初始化失败原因 - `ServletContext`初始化异常堆栈 - `BeanCreationException`或`UnsatisfiedDependencyException` --- #### 8. **临时简化配置** **验证方法**: - 注释掉非核心功能(如定时任务、安全配置): ```java // @Scheduled(fixedDelay=1000) // 引用[4]中的定时任务 public void sendQuotes() { ... } ``` - 逐步恢复功能以定位问题模块。 --- ### 示例错误日志分析 ```log 2023-10-05 12:00:00.ERROR [main] o.s.b.SpringApplication - Application run failed org.springframework.context.ApplicationContextException: Unable to start web server Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] failed to start ``` **可能原因**: - `TomcatEmbeddedContext`初始化失败,通常由Servlet或Filter注册冲突引起[^1][^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值