【问题标题】:Unable to start spring boot application NoClassDefFoundError无法启动 Spring Boot 应用程序 NoClassDefFoundError
【发布时间】:2018-08-17 06:46:45
【问题描述】:

我已将 spring-boot-starter-parent 从 1.4.3 更改为 1.5.4

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

这是我的 java 应用程序文件

 @SpringBootApplication
    @ComponentScan("com.test")
    @EnableCaching
    @EnableAsync
    @EnableAspectJAutoProxy
    @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class })
public class Application {

当我启动我的服务器时,它会抛出以下错误。根据依赖关系,它应该处理依赖的 jar,例如 spring-boot

感谢任何帮助。

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/ErrorPage
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:73)
    at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:59)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1581)

【问题讨论】:

  • 为什么要排除DataSourceAutoConfigurationWebMvcAutoConfiguration?可能嵌入式 tomcat 的某些依赖项没有正确配置。如果您想覆盖一些自动配置,您可以扩展相应的适配器类,而无需手动重写整个配置
  • @SrThompson 排除 DataSource 和 AutoConfiguration 不会影响 tomcat 配置。

标签: spring spring-boot spring-boot-starter


【解决方案1】:

com.xyz.asr.autoconfigure.asr.tomcat.AsrEmbeddedTomcatCustomizercustomize 方法中的一些代码引用了类org.springframework.boot.context.embedded.ErrorPage。 Spring Boot 1.5 中不存在该类。 ErrorPage 的正确完全限定名称是 org.springframework.boot.web.servlet.ErrorPage

AsrEmbeddedTomcatCustomizer 需要更新为使用org.springframework.boot.web.servlet.ErrorPage

【讨论】:

    【解决方案2】:

    问题在于 Spring 版本。

    由于 Spring Boot 版本 1.5.4 和 1.5.2 在其中一个子项目中混在一起。为它创建了问题 9543。

    从 POM 文件中移除 spring-web 依赖,并将 spring-boot-starter-web 放入 POM 中。

    【讨论】:

    猜你喜欢
    • 2015-05-10
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2021-11-25
    相关资源
    最近更新 更多