티스토리 뷰

Spring

[SpringBoot] Java 17 & SpringBoot 2.7 버전업(자바 17 & 스프링부트 2.7 버전업)

망나니개발자 2024. 7. 16. 10:00
반응형

회사에서 관리중인 프로젝트가 크게 2가지가 있다. 하나는 스프링 부트 3.2까지 올려두었는데, 다른 프로젝트도 맞춰서 3.2까지 올려주려고 한다. 확인해보니 다른 스프링 부트 2.5.14 버전에 머물러 있어서, 3.2까지 올리기 위해 먼저 스프링 부트 2.7.18 및 자바 17로 버전업 하였다. 그 과정에서 해결했던 내용들을 정리하였다.

 

 

 

1. Java 17 & SpringBoot 2.7 버전업(자바 17 & 스프링부트 2.7 버전업)


[ Java 17 & SpringBoot 2.7 버전업 ]

LomboK 1.18.22 버전업

자바 버전을 1.8에서 17으로 올림에 따라 자바 컴파일 시에 롬복에서 다음과 같은 문제가 발생하였다.

자바 17과 호환되도록 롬복 버전을 1.18.22로 맞춰 올려주도록 하자.

> java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x7474066c) 
cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) 
because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x7474066c

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

 

 

 

springdoc 1.6.9 버전업

해당 내용은 사내에서 api 문서화를 위해 사용하는 springdoc 버전에 의한 문제였다. 기존의 springdoc 버전은 1.5.5였는데, 스프링부트 2.7에 적합한 버전은 1.6.9 버전이다. 따라서 해당 문제가 발생했다면 다음과 같이 버전을 높여주도록 하자.

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.webjars.WebJarAssetLocator.scanForWebJars(WebJarAssetLocator.java:183)

The following method did not exist:

    'io.github.classgraph.ClassGraph io.github.classgraph.ClassGraph.acceptPaths(java.lang.String[])'

The calling method's class, org.webjars.WebJarAssetLocator, was loaded from the following location:

    jar:file:/home/gabriel/.m2/repository/org/webjars/webjars-locator-core/0.50/webjars-locator-core-0.50.jar!/org/webjars/WebJarAssetLocator.class

The called method's class, io.github.classgraph.ClassGraph, is available from the following locations:

    jar:file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar!/io/github/classgraph/ClassGraph.class

The called method's class hierarchy was loaded from the following locations:

    io.github.classgraph.ClassGraph: file:/home/gabriel/.m2/repository/io/github/classgraph/classgraph/4.8.69/classgraph-4.8.69.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.webjars.WebJarAssetLocator and io.github.classgraph.ClassGraph

 

 

 

SpringCloud 2021.0.8 버전업

스프링 부트 2.7에 맞는 스프링 클라우드 버전은 2021.0.8이다. 따라서 스프링 클라우드 버전 역시 맞춰주도록 하자.

2024-06-12 18:12:07.416  WARN 76708 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - 
cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compositeCompatibilityVerifier' 
defined in class path resource [org/springframework/cloud/configuration/CompatibilityVerifierAutoConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.cloud.configuration.CompositeCompatibilityVerifier]: Factory method 'compositeCompatibilityVerifier' threw exception; 
nested exception is org.springframework.cloud.configuration.CompatibilityNotMetException: Spring Cloud/ Spring Boot version compatibility checks have failed: 
[[VerificationResult@2472a75c description = 'Spring Boot [2.7.17] is not compatible with this Spring Cloud release train', 
action = 'Change Spring Boot version to one of the following versions [2.4.x, 2.5.x] .

 

 

 

Gradle compieJava 버전 설정

그래이들을 통해 테스트를 진행하려고 하니 다음과 같은 에러가 발생하였다.

w: Inconsistent JVM-target compatibility detected for tasks 'compileJava' (21) and 'compileKotlin' (17).

 

 

확인해보니 build.gradle.kts 에서 자바 컴파일 버전을 명시하지 않아서 발생하는 문제였고, toolchain을 통해 자바 버전을 명시하여 해결하였다.

subprojects {

    ...

    java {
        toolchain {
            languageVersion.set(JavaLanguageVersion.of(17))
        }
    }

    tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "17"
        }
    }
}

 

 

 

Toolchain은 자바 프로젝트를 빌드하고 실행하기 위한 도구의 모음으로, 일반적으로 설치된 JRE 또는 JDK를 통해 제공된다. Gradle은 기본적으로 Gradle 자체와 빌드중인 JVM 프로젝트와 동일한 toolchain을 사용하는데, 서로 다른 환경에서는 이것이 일원화되지 않았을 수 있다. 따라서 빌드의 일관성과 재현가능성을 높이고 요구사항을 보다 명확하게 하기 위해 이를 설정할 수 있다.

 

 

mysql-connector-java 버전 명시

스프링 부트 2.7부터는 버전 관리 대상에서 mysql-connector-java 라이브러리가 제거되었다. 따라서 기존에 버전을 명시하지 않고 사용하고 있었다면, 이를 개선해주도록 하자.

implementation("mysql:mysql-connector-java")
implementation("mysql:mysql-connector-java:8.0.33")

 

 

 

IntelliJ 설정 변경

인텔리제이에서 변경된 버전으로 실행하려고 하면 다음과 같은 에러가 발생할 수 있다.

class file has wrong version 61.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

 

 

이러한 경우에는 다음과 같이 프로젝트 설정을 반영해주면 된다.

 

 

 

 

 

회사에서 관리중인 프로젝트가 크게 2가지가 있다. 하나는 스프링 부트 3.2까지 올려두었는데, 다른 프로젝트도 맞춰서 3.2까지 올려주려고 한다. 확인해보니 다른 스프링 부트 2.5.14 버전에 머물러 있어서, 3.2까지 올리기 위해 먼저 스프링 부트 2.7.18 및 자바 17로 버전업 하였다. 그 과정에서 해결했댄 내용들을 정리하였다.

다음으로는 자바 21과 스프링 부트 3.2까지 올렸던 내용이 이어서 올라갈 예정이다.

 

 

 

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함