의존관계

    [Spring] 다양한 의존 관계 주입 방법

    생성자 주입 생성자를 통해서 의존 관계를 주입 받는 방법으로 호출 시점에 딱 1번만 호출이 된다. → 이후에 변화가 없고, 꼭 필요한 필수 의존관계에 사용된다. public class StudnetServiceImpl implements StudentService{ private final StudentRepository studentRepository; private final GradePolicy gradePolicy; @Autowired public StudnetServiceImpl(StudentRepository studentRepository, GradePolicy gradePolicy) { this.studentRepository = studentRepository; this.gradePoli..

    [Spring] 스프링 컨테이너

    [Spring] 스프링 컨테이너

    스프링 컨테이너 생성 스프링 컨테이너를 생성할 때는 ApplicationContext라는 인터페이스를 이용하며, 상황에 맞는 구현 객체를 생성해주면 된다. 스프링 부트의 등장 이후 Annotation을 많이 사용하기 때문에 AnnotationConfigApplicationContext를 주로 이용한다. 인자로는 @Configuration 어노테이션이 붙은 설정 클래스 파일을 넘겨주면 된다. ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class); 스프링 컨테이너의 생성 과정 스프링 컨테이너를 생성할 때 매개 변수로 Configuration 클래스 파일을 넘겨주는데, 스프링 컨테이너는 이 클래스 파일을 참고하여 빈 이름과 객..