Spring

java.lang.NoClassDefFoundError가 발생하는 스프링 버전을 업그레이드한 후:

기록만이살길 2022. 12. 21. 23:10
반응형

java.lang.NoClassDefFoundError가 발생하는 스프링 버전을 업그레이드한 후:

1. 질문(문제점):

우리가 가지고 있는 여러 프로젝트에서 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

확인했고 문서에 따르면 이 클래스는 현재 스프링 코어 버전에서 사용할 수 있어야 합니다 . 어노테이션/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 의존성 트리, 모든 스프링 발생:

[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

2. 해결방안:

참조 : 문서

Spring IO 플랫폼의 일부인 아티팩트가 version 없이 선언되면 미리 정의된 의존성 버전이 사용되며 spring-core의 경우

org.springframework 스프링 코어 5.0.13.RELEASE

https://docs.spring.io/spring/docs/5.0.13.RELEASE/javadoc-api/org/springframework/core/annotation/ 에 MergedAnnotations 클래스가 없습니다.

선택한 버전으로 의존성을 선언합니다.

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

업데이트 (이전 답변이 약간 오해의 소지가 있음)

버전을 명시적으로 선언할 필요는 없습니다. 설명서의 의존성 관리 섹션에서는 다음을 언급합니다.

Spring Boot의 각 릴리스는 지원하는 선별된 의존성 List을 제공합니다. 실제로 빌드 구성에서 이러한 의존성에 대한 버전을 제공할 필요가 없습니다. Spring Boot가 이를 관리하기 때문입니다. Spring Boot 자체를 업그레이드하면 이러한 의존성도 일관된 방식으로 업그레이드됩니다.

또한 스타터 부모를 상속할 때 필요한 업그레이드 수정 사항은 여기에서 설명합니다.

반응형