반응형
Jake Seo
제이크서 위키 블로그
Jake Seo
전체 방문자
오늘
어제
  • 분류 전체보기 (715)
    • 일상, 일기 (0)
    • 백준 문제풀이 (1)
    • 릿코드 문제풀이 (2)
    • 알고리즘 이론 (10)
      • 기본 이론 (2)
      • 배열과 문자열 (8)
    • 데이터베이스 (15)
      • Planet Scale (1)
      • MSSQL (9)
      • 디비 기본 개념 (1)
      • SQLite 직접 만들어보기 (4)
    • 보안 (7)
    • 설계 (1)
    • 네트워크 (17)
      • HTTP (9)
      • OSI Layers (5)
    • 회고 (31)
      • 연간 회고 (2)
      • 주간 회고 (29)
    • 인프라 (52)
      • 도커 (12)
      • AWS (9)
      • 용어 (21)
      • 웹 성능 (1)
      • 대규모 서비스를 지탱하는 기술 (9)
    • 깃 (7)
    • 빌드 도구 (7)
      • 메이븐 (6)
      • 그레이들 (0)
    • Java (135)
      • 이펙티브 자바 (73)
      • 자바 API (4)
      • 자바 잡지식 (30)
      • 자바 디자인 패턴 (21)
      • 톰캣 (Tomcat) (7)
    • 프레임워크 (64)
      • next.js (14)
      • 스프링 프레임워크 (28)
      • 토비의 스프링 (6)
      • 스프링 부트 (3)
      • JPA (Java Persistence API) (5)
      • Nest.js (8)
    • 프론트엔드 (48)
      • 다크모드 (1)
      • 노드 패키지 관리 매니저 (3)
      • CSS (19)
      • Web API (11)
      • tailwind-css (1)
      • React (5)
      • React 새 공식문서 요약 (1)
      • HTML (Markup Language) (5)
    • 자바스크립트 (108)
      • 모던 자바스크립트 (31)
      • 개념 (31)
      • 정규표현식 (5)
      • 코드 스니펫 (1)
      • 라이브러리 (6)
      • 인터뷰 (24)
      • 웹개발자를 위한 자바스크립트의 모든 것 (6)
      • 팁 (2)
    • Typescript (49)
    • 리눅스와 유닉스 (10)
    • Computer Science (1)
      • Compiler (1)
    • IDE (3)
      • VSCODE (1)
      • IntelliJ (2)
    • 세미나 & 컨퍼런스 (1)
    • 용어 (개발용어) (16)
      • 함수형 프로그래밍 용어들 (1)
    • ORM (2)
      • Prisma (2)
    • NODEJS (2)
    • cypress (1)
    • 리액트 네이티브 (React Native) (31)
    • 러스트 (Rust) (15)
    • 코틀린 (Kotlin) (4)
      • 자바에서 코틀린으로 (4)
    • 정규표현식 (3)
    • 구글 애널리틱스 (GA) (1)
    • SEO (2)
    • UML (2)
    • 맛탐험 (2)
    • 리팩토링 (1)
    • 서평 (2)
    • 소프트웨어 공학 (18)
      • 테스팅 (16)
      • 개발 프로세스 (1)
    • 교육학 (1)
    • 삶의 지혜, 통찰 (1)
    • Chat GPT (2)
    • 쉘스크립트 (1)
    • 컴파일 (2)
    • Dart (12)
    • 코드팩토리의 플러터 프로그래밍 (4)
    • 플러터 (17)
    • 안드로이드 스튜디오 (1)
    • 윈도우즈 (1)
    • 잡다한 백엔드 지식 (1)
    • 디자인 패턴 (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 메이븐 라이프사이클
  • 자바스크립트 인터뷰
  • 작업기억공간
  • 메이븐 골
  • 자바스크립트 면접
  • 추상 팩터리 패턴
  • 싱글톤 패턴
  • Javadoc 자바독 자바주석 주석 Comment
  • 싱글턴
  • 자료구조
  • 객체복사
  • Java
  • 메이븐 페이즈
  • rust
  • 자바 디자인패턴
  • 이펙티브자바
  • next js app
  • pnpm
  • 슬로우 쿼리
  • Pre-rendering
  • 러스트
  • 빈 검증
  • NEXT JS
  • 플라이웨이트패턴
  • 서버리스 컴퓨팅
  • prerendering
  • MSSQL
  • 싱글톤
  • 이펙티브 자바 item9
  • 느린 쿼리
  • 자바
  • 자바스크립트
  • 프로그래머의 뇌
  • serverless computing
  • item8
  • 토비의 스프링
  • 자바 검증
  • 스프링 검증
  • Next.js
  • 도커공식문서
  • try-with-resources
  • item9
  • 외래키 제약조건
  • 알고리즘
  • bean Validation
  • 참조 해제
  • 이펙티브 자바
  • 팩터리 메서드 패턴
  • 디자인패턴
  • item7

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Jake Seo

제이크서 위키 블로그

프레임워크/스프링 프레임워크

스프링 프레임워크 버전 4.2에서 4.3 업그레이드시 변화사항

2023. 3. 23. 14:36

개요

스프링 프레임워크 버전 4.2에서 4.3으로 버전업을 수행했을 때 어떠한 변화가 일어나는지 알아보자.

시멘틱 버저닝에 대한 설명

아래는 스프링 프레임워크 버저닝에 대한 오피셜한 설명입니다.

  • MAJOR, if incremented, may involve a significant amount of work to upgrade. / Major features and potential breaking changes
  • MINOR, if incremented, should involve little to no work to upgrade. / Backward compatible features
  • PATCH, if incremented, should involve no work. / Backward compatible fixes and improvements

이번 버전업은 MINOR 에 해당하는 버전업으로 과거 버전과 완벽하게 호환됩니다.

개선사항

Implicit Constructor Injection

  • 생성자를 통한 의존성 주입 시에 @Autowired 가 없어도 자동으로 타입에 맞는 빈을 탐색하여 가져오는 기능
  • 스프링 진영에서 생각하는 가장 이상적인 의존성 주입 방향성입니다.
@Service
public class FooService {

    private final FooRepository repository;

    @Autowired
    public FooService(FooRepository repository) {
        this.repository = repository
    }
}
@Service
public class FooService {

    private final FooRepository repository;

    public FooService(FooRepository repository) {
        this.repository = repository
    }
}

단, FooRepository 타입의 빈은 컨테이너 상에 단 하나만 존재하여야 함

@Configuration Implicit Constructor Injection

  • 위와 동일한 기능이 @Configuration 애노테이션의 클래스에서도 가능
@Configuration
public class FooConfiguration {

    private final FooRepository repository;

    public FooConfiguration(FooRepository repository) {
        this.repository = repository;
    }

    @Bean
    public FooService fooService() {
        return new FooService(this.repository);
    }
}

Default Methods Support

  • 자바 Interface 의 default 메서드를 통한 빈 생성이나 라이프사이클 메서드를 이용할 수 있습니다.
package com.logicbig.example;

import javax.annotation.PostConstruct;

public interface IMyBean {
  @PostConstruct
  default void init() {
      System.out.println("post construct: "+this.getClass().getSimpleName());
  }
}
package com.logicbig.example;

import org.springframework.context.annotation.Bean;

public interface IMyConfig {
  @Bean
  default MyBean myBean() {
      return new MyBean();
  }
}
package com.logicbig.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyConfig implements IMyConfig {
  public static void main(String[] args) {
      ApplicationContext context =
              new AnnotationConfigApplicationContext(MyConfig.class);
      MyBean bean = context.getBean(MyBean.class);
      bean.showMessage("a test message");
  }
}

HTTP HEAD and HTTP OPTIONS

  • HTTP Method 별 매핑 지원
    • @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PatchMapping
  • @RequestMapping(method = RequestMethod.GET) 보다 짧고, 의도가 명확합니다.
  • 의도치 않은 HTTP method 를 제공하여 생길 수 있는 실수를 방지합니다.

스코프별 빈 생성 가능

  • @RequestScope, @SessionScope
  • 해당 스코프에서만 존재하는 빈 생성이 가능합니다.
  • 긴 생명주기가 필요 없는 작업의 경우 유용합니다.
@Service
@RequestScope
public class UserContextService {

    private User currentUser;

    @Autowired
    private UserRepository userRepository;

    public void setCurrentUser(String username) {
        this.currentUser = userRepository.findByUsername(username);
    }

    public User getCurrentUser() {
        return currentUser;
    }
}

@Controller
@RequestMapping("/profile")
public class ProfileController {

    @Autowired
    private UserContextService userContextService;

    @GetMapping
    public String showProfile(Model model) {
        User currentUser = userContextService.getCurrentUser();
        model.addAttribute("currentUser", currentUser);
        return "profile";
    }
}

@RestControllerAdvice

  • Rest API 에서 예외가 발생했을 때 전체적 관리 가능한 애노테이션
  • Custom Exception 클래스들을 생성하고, 이에 따른 에러 메세지를 일관성 있게 관리할 수 있습니다.
@RestControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(value = { InvalidRequestException.class })
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ErrorMessage handleInvalidRequestException(InvalidRequestException ex) {
        return new ErrorMessage(ex.getMessage());
    }

    @ExceptionHandler(value = { ResourceNotFoundException.class })
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ErrorMessage handleResourceNotFoundException(ResourceNotFoundException ex) {
        return new ErrorMessage(ex.getMessage());
    }

    // other exception handlers...
}

@RequestAttribute

  • 요청에서 온 값을 별도의 클렌징 과정 없이 바로 받아보는 애노테이션
  • 별 것 아닌 것 같아 보이지만, 코드에서 사용되는 입력값들을 파라미터에서 한눈에 볼 수 있다는 점이 큽니다.

before

@Controller
@RequestMapping("/example")
public class ExampleController {

  @RequestMapping("/showUserId", method = RequestMethod.GET)
  public String showUserId(HttpServletRequest request, Model model) {
    String b2cId = request.getParameter("b2cId"); // 추가 변수 선언 필요
    model.addAttribute("b2cId", b2cId);
    return "showUserId";
  }
}

after

@Controller
@RequestMapping("/example")
public class ExampleController {

  @GetMapping("/showUserId")
  public String showUserId(@RequestAttribute("b2cId") String b2cId, Model model) {
    model.addAttribute("b2cId", b2cId);
    return "showUserId";
  }
}

@SessionAttribute

  • 세션에 있는 값을 별도의 파싱 없이 바로 받아보는 애노테이션

before

@GetMapping("/showUser")
public String showUser(HttpSession session, Model model) {
  String b2cId = (String) session.getAttribute("b2c_id"); // 강제 타입 캐스팅이 필요함.
  model.addAttribute("b2cId", b2cId);
  return "showUser";
}

after

@GetMapping("/showUser")
public String showUser(@SessionAttribute("b2cId") String b2cId, Model model) {
  model.addAttribute("b2cId", b2cId);
  return "showUser";
}

조금 더 높은 버전의 서드파티 라이브러리 이용 가능

  • Hibernate ORM 5.2 (still supporting 4.2/4.3 and 5.0/5.1 as well, with 3.6 deprecated now)
  • Jackson 2.8 (minimum raised to Jackson 2.6+ as of Spring 4.3)
  • OkHttp 3.x (still supporting OkHttp 2.x side by side)
  • Netty 4.1
  • Undertow 1.4
  • Tomcat 8.5.2 as well as 9.0 M6

보안

  • 현재 사용 중인 4.2.4 버전에 보안 문제 13개 존재
    • https://mvnrepository.com/artifact/org.springframework/spring-core/4.2.4.RELEASE
  • 4.3.30 까지 가면 보안 문제는 5개로 줄어들음
    • https://mvnrepository.com/artifact/org.springframework/spring-core/4.3.30.RELEASE

레퍼런스

  • 스프링 공식 마이그레이션 가이드
  • 밸덩 마이그레이션 가이드
반응형
저작자표시 비영리 (새창열림)

'프레임워크 > 스프링 프레임워크' 카테고리의 다른 글

@EnableRedisHttpSession 은 어떻게 동작하는가? (feat. 스프링 세션에 레디스 활용하기)  (0) 2023.04.19
RedirectAttributes 란? (feat. addFlashAttribute 에 대한 설명 포함)  (0) 2023.04.17
DispatchServlet.doDispatch() 함수 끝까지 따라가서 HandlerMapping 과 HandlerAdapter 알아보기  (0) 2023.01.30
스프링 객체 검증 (Validation) 적용하기  (0) 2022.05.29
asciidoctor 를 통한 Spring REST Docs 자동 생성 세팅하기  (2) 2022.05.18
    '프레임워크/스프링 프레임워크' 카테고리의 다른 글
    • @EnableRedisHttpSession 은 어떻게 동작하는가? (feat. 스프링 세션에 레디스 활용하기)
    • RedirectAttributes 란? (feat. addFlashAttribute 에 대한 설명 포함)
    • DispatchServlet.doDispatch() 함수 끝까지 따라가서 HandlerMapping 과 HandlerAdapter 알아보기
    • 스프링 객체 검증 (Validation) 적용하기
    Jake Seo
    Jake Seo
    ✔ 잘 보셨다면 광고 한번 클릭해주시면 큰 힘이 됩니다. ✔ 댓글로 틀린 부분을 지적해주시면 기분 나빠하지 않고 수정합니다. ✔ 많은 퇴고를 거친 글이 좋은 글이 된다고 생각합니다. ✔ 간결하고 명료하게 사람들을 이해 시키는 것을 목표로 합니다.

    티스토리툴바