Spring Framework/Spring

Spring Framework/Spring

스프링 FactoryBean: 생성자 주입과 필드 주입 시 프록시 객체의 동작 차이

FactoryBean을 구현한 클래스에서 @Transactional을 적용한 메서드를 가진 Service 클래스를 주입받을 때 생성자 주입과 필드 주입 방식에 있어 발생하는 차이점에 대해 정리하고자 합니다. 일반적인 빈 생성의 경우에는 생성자 주입과 필드 주입 2가지 경우 모두 AOP 프록시 객체가 잘 전달이 되는데 위 상황에서는 다르게 동작하는 것을 발견했습니다. 0. Given:/** Foo.java */@RequiredArgsConstructorpublic class Foo { private final FooService fooService; public void bar() { fooService.bar(); }}/** FooService.java */@Servicepublic class..

Spring Framework/Spring

Spring AOP 개념 정리 및 Aspect 적용 방법 - annotation 활용

AOP (Aspect Oriented Programming)OOP 개발을 하면 핵심 기능과 부가 기능이 나뉘는데, AOP는 부가 기능을 관점(Aspect)으로 정의하여, 핵심 기능에서 부가 기능을 분리하여 설계하고 구현할 수 있게 도와줍니다. 부가 기능은 핵심 기능을 도와주는 기능으로 모듈화 되어 핵심 기능과 분리되어 구현할 수 있습니다.Class A { method a() { AAAA business Logic.. BBBB } method b() { AAAA business Logic.. BBBB }} Class B { me..

Spring Framework/Spring

[Spring] 스프링 FactoryBean 이해하기 - Custom Bean 생성방법

FactoryBean이란BeanFactory내에 사용되는 객체가 구현할 인터페이스입니다.해당 인터페이스를 구현하는 경우, bean instance 자체로 노출되어 사용되는 것이 아니라, 객체를 노출할 factory로 사용됩니다.Interface to be implemented by objects used within a BeanFactory which are themselves factories for individual objects. If a bean implements this interface, it is used as a factory for an object to expose, not directly as a bean instance that will be exposed itself. 스프링 ..

Spring Framework/Spring

[Spring] Spring Batch Tasklet 작업 단위 이해하기 - StepContribution, ChunkContext

Tasklet이란간단한 단위의 작업을 수행하는 Batch Step을 정의할 때 사용하는 인터페이스입니다,.Step은 보통 Tasklet, Chunk 단위로 작업을 처리합니다.Tasklet은 하나의 작업 단위를 처리하는 인터페이스배치 작업에서 독립적이고 작은 단위의 작업을 정의하는데 사용합니다. Tasklet Interface 구조execute() 단일 메서드를 가지고 있습니다.public interface Tasklet { RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;}매개변수 : StepContribution, ChunkContext반환값 : RepeatStatusRepe..