当前位置: 首页 > 知识库问答 >
问题:

升级spring版本后获得java。lang.NoClassDefFoundError:

钦宏义
2023-03-14

我正在尝试在我们现有的多个项目中将spring从2.1.1升级到2.2.0。我已经在几个项目中完成了这项工作,一切都很顺利。

在当前项目中,我做了相同的更改:

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

<properties>
        <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
        <spring.boot.version>2.2.0.RELEASE</spring.boot.version>
    ...
    ...

</properties>

<dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
            </dependency>
        .....
        .....
</dependencyManagement>

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
...
</dependencies>

现在,当我尝试启动我的应用程序时,我遇到以下错误:

Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/MergedAnnotations$SearchStrategy

我检查过,根据文档,这个类应该在我当前的spring core版本中可用:https://docs.spring.io/spring/docs/5.2.0.RELEASE/javadoc-api/org/springframework/core/annotation/MergedAnnotations.SearchStrategy.html

堆栈跟踪:

java.lang.NoClassDefFoundError: org/springframework/core/annotation/MergedAnnotations$SearchStrategy
        at org.springframework.boot.BeanDefinitionLoader.isComponent(BeanDefinitionLoader.java:279) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:156) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:136) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.BeanDefinitionLoader.load(BeanDefinitionLoader.java:128) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplication.load(SpringApplication.java:691) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:197) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:152) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:132) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:92) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171) [spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]

maven dependencies树,所有Spring事件:

[INFO] +- org.springframework.security:spring-security-config:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-context:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-context:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.0.RELEASE:provided
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.0.RELEASE:provided
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.2.0.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:5.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:5.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-tx:jar:5.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-tx:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:5.2.0.RELEASE:compile
[INFO] +- org.apache.cxf:cxf-spring-boot-starter-jaxrs:jar:3.2.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.apache.cxf:cxf-spring-boot-autoconfigure:jar:3.2.5:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-actuator:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.2.0.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.2.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.2.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.2.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.2.0.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.2.0.RELEASE:test
[INFO] |  +- org.springframework:spring-test:jar:5.2.0.RELEASE:test
[INFO] |  +- org.springframework:spring-test:jar:5.2.0.RELEASE:test
[INFO] +- org.springframework.cloud:spring-cloud-config-client:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.cloud:spring-cloud-config-client:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-commons:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-commons:jar:2.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:5.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework.cloud:spring-cloud-context:jar:2.2.0.RELEASE:compile
[INFO] |  \- org.springframework.cloud:spring-cloud-context:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.retry:spring-retry:jar:1.2.4.RELEASE:compile
[INFO] +- org.springframework.retry:spring-retry:jar:1.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:5.2.0.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.2.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.2.0.RELEASE:compile
[INFO]    \- org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.2.0.RELEASE:compile
[INFO]    \- org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.2.0.RELEASE:compile
[INFO]       +- org.springframework.cloud:spring-cloud-starter:jar:2.2.0.RELEASE:compile
[INFO]       +- org.springframework.cloud:spring-cloud-starter:jar:2.2.0.RELEASE:compile
[INFO]       |  \- org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
[INFO]       |  \- org.springframework.security:spring-security-rsa:jar:1.0.7.RELEASE:compile
[INFO]       +- org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.0.RELEASE:compile
[INFO]       +- org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.0.RELEASE:compile
[INFO]       |  +- org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.0.RELEASE:compile
[INFO]       |  +- org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.0.RELEASE:compile
[INFO]       |  |  \- org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.0.RELEASE:compile
[INFO]       |  |  \- org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.0.RELEASE:compile
[INFO]       |  \- io.github.openfeign.form:feign-form-spring:jar:3.8.0:compile

共有1个答案

怀飞扬
2023-03-14

参考:文件

当在没有版本的情况下声明Spring IO平台的一部分时,将使用依赖关系的预定义版本,而对于Spring core则是

组织。springframeworkSpring芯5.0.13。发布

https://docs.spring.io/spring/docs/5.0.13.RELEASE/javadoc-api/org/springframework/core/annotation/缺少MergedAnnotions类。

用所选版本声明依赖关系

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.2.0.RELEASE</version>
    </dependency>

更新(我之前的回答似乎有点误导)

不需要明确声明版本。文档的依赖关系管理部分提到了以下内容。

Spring Boot的每个版本都提供了它所支持的依赖项的详细列表。实际上,您不需要在构建配置中为任何这些依赖项提供版本,因为Spring Boot会为您管理这些依赖项。升级Spring Boot本身时,这些依赖项也会以一致的方式升级。

此外,这里还解释了在插入starter父级时所需的升级修改

 类似资料:
  • 我在Ubuntu18.04上使用ELasticsearch。当我尝试运行“./elasticsearch-setup-passwords”脚本时,它显示以下错误。 未来版本的Elasticsearch将需要Java 11;您的Java版本[/usr/lib/jvm/java-8-openjdk-amd64/jre]不符合此要求 但当我检查Jaa版本时,它显示的是Java 11号。 我把Java从8

  • 0.2.X

  • 从 0.8.x, 0.9.x, 0.10.0.x, 0.10.1.x, 0.10.2.x, 0.11.0.x 升级到1.0.0 Kafka 1.0.0 介绍了通信协议方面的改变。 遵循下面的滚动升级计划,可以保证您在升级过程中不用停机。 在升级之前,请先查看1.0.0版本中显著的变化。 滚动升级计划: 更新所有代理上的server.properties 并添加以下属性: CURRENT_KAFKA

  • 无非就3个原因吧 为了fix bug 为了新特性 为了爱,就是要追新 从1.a.38开始的版本,升级到最新版的成本都不大. 做到100%兼容是不现实的,但可以肯定的是, 遇到的问题的均有解决的办法. 有些兼容性问题,属于"错误"得到修正,老版本能这样写是"bug", ^_^ 这是一个汇总帖子,随时更新, 也会按版本的增长继续增长.... 请先浏览当前版本到最新版的发行注记,然后再看本列表 IE下a

  • MinDoc 根据发布系统功能不同可分为两步进行升级。有些用户可能会自定义了模板,覆盖时请注意备份。尤其是要注意备份配置文件和数据库。 版本查看 通过命令行执行如下命令: ./mindoc version 会看到如下的版本信息: #当前安装的版本版本号 MinDoc current version => v1.0 #最新版本版本号 MinDoc last version => v1.0 一、覆

  • 0.2.X 0.2.2 修改package.json "bui-weex": "^0.2.2" 更新内容 bui-weex无需显式引用,通过 Vue plugin方式注入到全局; 重构组件:弹出框、弹出层、下拉菜单、ActionSheet,并统一使用v-model调用方式; 重构组件:单选、复选等组件,并统一使用v-model调用方式; 重构组件: 选项卡组件,并统一使用v-model调用方式,配