
Spring AOT란? Spring 6부터 Spring AOT(Ahead of Time; 사전 최적화) 기능이 도입되었다. 기존에는 Spring Native 프로젝트에서 실험해왔던 기능인데, 이제 Spring core에 포함되었다.

AOP란? 관점 지향 프로그래밍은 메서드의 공통 로직(로깅 등)을 비즈니스 로직하고자 하는 프로그래밍 기법이다. 코드에 불필요한 중복을 줄이고 비즈니스 로직에만 집중할 수 있다. Spring에서는 AOP를 지원하기 위해 JDK 동적 프록시(java.lang.reflect.proxy)를 이용해 프록시 객체를 만든다. 그러나 원본 클래스가 인터페이스를 구현하지 않는 경우에는 예외적으로 CGLIB을 이용해 프록시를 만든다. (설정 파일이 CGLIB 프록시가 되는 것 처럼) AspectJ? AspectJ는 Java에서 AOP를 지원하기 위해 만들어진 오픈 소스 프로젝트이다. 자바 기반 문법을 사용하지만, 순수 자바와는 다소 차이가 있고, “.aj” 의 확장자를 가진다. package test; public as..
SpEL SpEL(Spring Expression Language)이란 런타임에서 객체에 대한 쿼리와 조작을 지원하는 강력한 표현 언어이다. The Spring Expression Language (SpEL) is a powerful expression language that supports querying and manipulating an object graph at runtime. 사용 예시 public void run() { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression("'Hello World'.concat('!')"); String message = (String) exp..

Null Safety Java는 기본적으로 null-safety를 표현할 수 없음. (안전을 위해 Optional을 사용 권장) Spring의 null-safety 어노테이션을 사용해 해당 매개변수, 반환 값, 필드가 null이 될 수 없음을 명시할 수 있음. (강제할 수는 없음.) @Nullable - 특정 매개변수, 반환 값, 필드가 null이 될 수 있음을 명시 @NonNull - 특정 매개변수, 반환 값, 필드가 null이 될 수 없음을 명시 @NonNullApi - null이 아닌 것을 매개변수, 반환 값의 기본 체계로 선언(패키지 수준) @NonNullFields - null이 아닌 것을 필드의 기본 체계로 선언(패키지 수준) public void print(@NonNull String mes..
Spring의 Resource 인터페이스 Java의 표준 java.net.URL의 클래스는 기능이 부족하다. classpath로부터 파일을 읽어올 수 없음 ServletContext로 부터의 상대경로로 파일을 읽어올 수 없음 특수 접두사에 대해 핸들러 등록이 복잡함 Spring은 Resource 인터페이스(org.springframework.core.io.Resource)를 만들어 여러 resource들을 추상화했다. Resource 인터페이스는 아래와 같다. public interface Resource extends InputStreamSource { boolean exists(); default boolean isReadable() { return exists(); } default boolean ..
@Qualifier @Qualifier 어노테이션을 통해 같은 타입의 빈이 여러개인 경우 주입받을 빈을 지정할 수 있다. package com.sample.spring.repository; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; @Repository @Qualifier("primaryRepository") public class SampleRepositoryImpl2 implements SampleRepository { public int getLastUserId() { return 200; } } package com.sample.spring..
ComponentScan 만약 프로그램의 규모가 커져서 등록해야 할 빈이 수백, 수천개라면 어떻게 해야할까? 의존관계 설정파일을 관리하는데 어머어머한 시간이 소요될 것이다. Spring context에서는 빈을 자동으로 찾아 등록(주입이 아니다)하는 Component scan 기능을 제공한다. 설정 파일에 @ComponentScan 어노테이션을 붙임으로써, Component scan을 사용할 수 있다. package com.sample.spring; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @Compon..
Spring context에서는 설정 파일을 통해 의존관계를 주입하는 방법 외에도 @Autowired 어노테이션을 통해 주입하는 방법을 지원한다. Setter 주입 package com.sample.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import com.sample.spring.repository.SampleRepository; import com.sample.spring.repository.SampleRepositoryImpl1..