티스토리 뷰

728x90
반응형

 

 

 

 

 

 

Java EE에서 Jakarta EE로의 전환

 

spring boot 3.x 버전은 java 17, jakarta EE 9+ 이상을 지원

spring boot 2.7 버전은 jakarta EE 8 을 지원

그 이하 버전은 java 1.8, java EE를 지원한다고 합니다.

 

java 17, wildFly 27.0.0.Final 에서는 잘 실행되는 프로젝트가

jakarta EE 8을 지원하는 wildFly 26에서는 서블릿 API 에러가 나면서 실행되지 않더라고요.

 

 

 

 

다음은 버전에 따라 생겼던 이슈들에 대해 해결한 방법입니다.

 

1. javax.servlet

아래와 같이 Request와 Session을 임포트하려고 했을 때 에러가 난다면

Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest

The import javax.servlet cannot be resolved

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

 

 

올바른 Servlet 패키지명으로 변경해주어야합니다.

Jakarta EE 9(Tomcat 10, TomEE 9, WildFly 22 Preview, GlassFish 6, Payara 6, Liberty 22 등)의 일부인

Servlet API 버전 5.0부터 패키지 이름이  javax.*에서  jakarta.* 로 변경되었습니다.

따라서 이러한 서버 버전 이상을 대상으로 하는 경우에는 jakarta로 변경하면 됩니다.

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

 

 

# 1번 문제 참고 사이트입니다.

https://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-jakarta-servlet-api-in-my-eclipse-project/4076706#4076706

 

How do I import the javax.servlet / jakarta.servlet API in my Eclipse project?

I want to develop with Servlets in Eclipse, but it says that the package javax.servlet / jakarta.servlet cannot be resolved. How can I add javax.servlet / jakarta.servlet package to my Eclipse proj...

stackoverflow.com

 

 

 

2. WebSecurityConfigurerAdapter

SpringSecurity에서 사용하는 WebSecurityConfigurerAdapter 에러.

The import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter cannot be resolved

import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

 

 

Spring Security 5.7.0-M2에서는 사용자가 컴포넌트 기반 보안 구성으로 전환하도록 권장하기 때문에 WebSecurityConfigurerAdapter를 더 이상 사용하지 않습니다.

이 경우에는 import한 부분을 주석처리해주고 configure에도 @override 를 지워줍니다.

 

//@Override
protected void configure(HttpSecurity http) throws Exception {
...

 

 

 

페이지별 권한 부분에서 사용했던 antMatchers는 requestMatchers로 바꿔줍니다.

 

http
    .httpBasic().disable()
    .cors().configurationSource(corsConfigurationSource())
    .and()
    .authorizeRequests()
        .requestMatchers(...  // antMatchers(...를 변경

 

반응형

 

 

 

# 2번 문제 참고 사이트입니다.

https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

 

Spring Security without the WebSecurityConfigurerAdapter

In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter, as we encourage users to move towards a component-based security configuration. To assist with the transition to this new style of configuration, we have compiled a list of common

spring.io

 

728x90

 

 

 

 

3. file path

Jar 프로젝트 일때에는 아래와 같이 파일경로를 가져왔었는데요.

String FILE_NAME = "a.csv";
String BASE_PATH = new File("").getAbsolutePath();
String FILE_PATH = BASE_PATH + FILE_NAME;
FileReader filereader = new FileReader(FILE_PATH);

 

 

War (wildFly) 로 바꾸고 나니 절대경로가 wildFly 서버쪽이 되더라구요.

아래와 같이 파일 절대경로를 가져오는 방법을 변경했습니다.

classpath: 뒤에부터는 프로젝트의 src/main/resources 다음부터 적어주시면 됩니다.

 

File file = new PathMatchingResourcePatternResolver().getResource("classpath:" + path).getFile();
String FILE_PATH = file.getAbsolutePath();

 

 

 

4. mybatis-spring

Invalid value type for attribute 'factoryBeanObjectType': java.lang.String 

이건 패키징과는 별개로 버전이슈가 있었던 내용입니다.

spring boot 버전을 2.x 에서 3.x으로 변경했을 때 mybatis-spring도 2.x에서 3.x으로 변경해주어야한다는 것..!

저는 spring boot 3.2.0을 썼고 아래와 같이 버전을 변경해주었더니 에러가 사라졌습니다.

<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>3.0.3</version>
</dependency>

 

 

 

 

참고했던 사이트들입니다.

 

 

https://post.dooray.io/we-dooray/tech-insight-ko/back-end/4173/

 

스프링 부트 3.0 으로 전환 - Dooray! POST

2022년 11월에 기존의 Spring framework 5 와 Spring Boot 2.X 버전을 대체하는 Spring framework 6와 Spring Boot 3 가 릴리즈되었습니다. 어떤 변화가 있고, 어떻게 설정해야 할지 알아봅니다

post.dooray.io

 

https://stackoverflow.com/questions/76580588/compatibility-spring-boot-3-x-and-spring-boot-2-7-x

 

Compatibility Spring Boot 3.x and Spring Boot 2.7.x?

There are two applications, first application work on Spring Boot 3.x, second application work on Spring Boot 2.7.x, from the second apllication pull dependensys which contains Entity at run Spring...

stackoverflow.com

 

https://www.samsungsds.com/kr/insights/java_jakarta.html

 

Java EE에서 Jakarta EE로의 전환 | 인사이트리포트 | 삼성SDS

자바 기술자라면 Java EE(Java Platform, Enterprise Edition) 또는 J2EE(Java 2 Platform, Enterprise Edition)를 들어봤을 것입니다. 자바를 이용한 서버 개발 플랫폼으로 한 때 엔터프라이즈 자바 기술을 선도하며 막

www.samsungsds.com

 

https://www.inflearn.com/questions/1088890/%EC%8A%A4%ED%94%84%EB%A7%81-%EB%B6%80%ED%8A%B8-2-x-%EB%B2%84%EC%A0%84-%EC%A7%80%EC%9B%90-%EC%A4%91%EB%8B%A8

 

스프링 부트 2.x 버전 지원 중단 - 인프런 | 질문 & 답변

안녕하세요! 최근에 강의를 수강하게 된 학생입니다.다름이 아니라 강의에서 말씀해주신 SpringBoot 2.7.6 버전을 설치하려고 하는데 start.spring.io에는 3.x버전들 밖에 보이지 않더라고요. 그래서 sprin

www.inflearn.com

 

 

 

 

끝!

 

 

728x90
반응형
댓글