컨테이너 주도 : 개발자 대신 컨테이너가 객체관리
의존성 주입 : 객체가 필요로 하는 의존성을 스프링이 알아서 해준다.
++) 컨테이너
전통적인 Spring 애플리케이션에서는 Root ApplicationContext와 WebApplicationContext를 따로 설정할 수 있고, 계층적 관계로 사용.
Spring Boot에서는 단일 컨텍스트가 기본이며, 별도로 전역 컨텍스트와 웹 컨텍스트를 나누지 않고 하나의 컨텍스트에서 모든 빈을 관리.
이유-->
Spring Boot에서는 자동 설정 덕분에 두 개로 나눌 필요 없이 하나의 컨텍스트로 모든 걸 처리
전통적인 Spring에서는 전역 빈과 웹 관련 빈을 분리해서 관리했지만, Spring Boot는 자동화가 되어 있어서 단일 컨텍스트로도 충분히 빈을 관리하고 애플리케이션을 운영할 수 있기 때문에 굳이 나눌 필요가 없다.
public class Service {
private final Repository repository;
public Service(Repository repository) {
this.repository = repository;
}
}
public class Service {
private Repository repository;
public void setRepository(Repository repository) {
this.repository = repository;
}
}
public class Service {
@Autowired
private Repository repository;
}
프로젝트할때는 간결하게 사용할 수 있는 필드주입을 사용하였다.
https://velog.io/@lee41180612/Spring-Bean-%EC%9D%B4%EB%9E%80
위 링크에서 빈이 생성되는 방식과 소멸되는 과정이 동작 방식임
결합도 감소
재사용성
유지보수 용이