ⓐ 제어 역전(IoC)
public class OrderService {
private OrderRepository orderRepository;
public OrderService() {
this.orderRepository = new OrderRepository();
}
}
@Service
public class OrderService {
private OrderRepository orderRepository;
@Autowired
public OrderService(OrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
}
- OrderService 객체의 생성과 OrderRepository 객체의 주임을 Spring IoC 컨테이너가 처리
ⓑ 의존성 주입(DI)
: 제어 역전의 방법 중 하나, 사용할 객체를 직접 생성하지 않고 외부 컨테이너가 생성한 객체를 주입받아 사용하는 방식
스프링에서 의존성을 주입"받는" 방식
- 생성자를 통한 의존성 주입
- 필드 객체 선언을 통한 의존성 주입
- setter 메서드를 통한 의존성 주입
public class DIController{
MyService myService;
public DIController(MyService myService){
this.myService = myService;
}
public class FieldInjectionController{
private MyService myService;
}
public class SetterInjectionController{
MyService myService;
public void setMyService(MyService myService){
this.myService = myService;
}
}
ⓒ 관점 지향 프로그래밍(AOP)
ⓓ 모듈
"Spring Boot makes it easy to create stand-alone,production-grade Spring based Applications that you can just run"