반응형
@PostConstruct는 다음과 같은 특징이 있습니다
- 의존성 주입이 완료된 후에 실행되어야 하는 method에 사용
- 해당 어노테이션은 다른 리소스에서 호출되지 않아도 수행
- 생성자 보다 늦게 호출된다
때문에 아래 코드처럼 application이 처음 부팅되는 순간 초기 설정이 필요한경우 이용합니다
@Component
@RequiredArgsConstructor
public class PostConstructBean {
private final TestService testService;
@PostConstruct
public void init() throws Exception {
testService.init();
}
}
반응형
'Spring' 카테고리의 다른 글
[Spring] MapStruct를 이용한 DTO <-> Entity 사용시 조인관계 매핑 (0) | 2023.03.01 |
---|---|
[Spring] @Valid List형태로 받으면 안되는 현상 해결방안 (0) | 2023.02.28 |
[Spring] Jasypt 사용시 @DataJpaTest 에러 (0) | 2023.02.24 |
[Spring] mapstruct를 이용한 DTO <-> Entity 변환 (0) | 2023.02.22 |
[SpringBoot 3.0] Jasypt를 이용한 설정값 암호화 (0) | 2023.02.22 |
댓글