전체 글
-
[SpringBoot] Dependency Injection 순서에 대해서카테고리 없음 2022. 11. 22. 14:01
Spring Dependency Injection 순서에 대해서 Spring boot 에서 Bean 을 주입 받을 때 그 순서를 잘 모르고 있었는데, 이번 기회에 정리해 보자. Service 레이어에서 여러 서비스에 대한 디펜던시를 주입받는 상황을 가정하여 밑과 같은 테스트 프로젝트를 생성하였다. @Service public class MainService { private final ConstructorService constructorService; private SetterService setterService; @Autowired private AutowiredService autowiredService; public MainService(ConstructorService constructorSe..
-
[Spring Boot] Field Injection 을 추천하지 않는 이유개발 2022. 11. 22. 13:57
Dependency Injection 방법 세가지와 왜 @Autowired 로 필드 인젝션이 추천되지 않는가? Dependency Injection 3가지 방법 Field Injection Setter Injection Constructor Injection 1. Field Inejction 변수 선언부에 @Autowired Annotation을 붙인다. @Component public class SampleController { @Autowired private SampleService sampleService; } 그런데 이 필드 주입은 추천 되는 방법이 아니다. 이 외에 이후에 소개 될 Constructor Injection 을 더 추천하는데, 왜 그럴까? 1.1 Field Injection 을 사..