@MappedSuperclass 이란? 객체들 간에 공통된 필드가 있을 때 @MappedSuperclass 객체를 상속받아서 이런 공통된 필드를 매핑해 준다. 예를 들어 여러 테이블에 생성자 ID, 생성 시간, 수정자 ID, 수정 시간의 속성이 필요하다면 객체마다 공통된 필드를 일일이 선언하는 것이 아닌 @MappedSuperclass 객체를 상속받으면 해결된다. 예제 아래 예제에서 두 개의 게시판 객체가 있는데 두개의 게시판은 생성자 ID, 생성 시간, 수정자 ID, 수정 시간의 공통 필드가 존재한다. 두 개의 게시판 객체를 @MappedSuperclass 선언된 객체를 상속받기 전과 후로 테스트해보았다. @MappedSuperclass 선언 전@Entitypublic class Board1 { ..
프로토타입 빈과 싱글톤 빈을 함께 사용 시 문제점 프로토 타입 빈과 싱글톤 빈을 함께 사용하면 의도한 대로 잘 동작하지 않을 수 있다. 아래 코드를 통해 알아보았다. 예제 아래 코드는 싱글톤 빈 내부에 있는 프로토타입 빈이 있을 때 2개의 클라이언트가 각각 싱글톤을 주입받으면 내부에 있는 프로토타입이 새로 생성되는지 알아보는 코드이다.public class SingletonWithPrototypeTest { @Test void singletonClientUsePrototype() { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ClientBean.class, ..
의존 관계 주입 방법생성자 주입수정자 주입(setter 주입)필드 주입일반 메서드 주입 생성자 주입 생성자를 통해서 의존 관계를 주입하는 것이다. 객체의 생성과 동시에 주입하며 불변, 필수 의존관계에 사용한다.@Servicepublic class ExService { private final ExRepository exRepository; // 생성자가 1개일 때 @Autowired 생략 가능 // @Autowired public exService(ExRepository exRepository) { this.exRepository = exRepository; }}※ 생성자가 1개만 있으면 @Autowired 생략 가능하다. 수정자 주입 setter라 불리는 ..
스프링 초기화 시점에서의 트랜잭션 AOP 적용 아래 예제를 통해 스프링 초기화 시점에서 트랜잭션이 적용되는지 테스트해보았다. 트랜잭션 적용X@SpringBootTestpublic class InitTest { @Test void execute() {} @TestConfiguration static class InitTestConfig { @Bean InitClass initClass() { return new InitClass(); } } @Slf4j static class InitClass { @PostConstruct @Transactional public void in..