사용자가 직접 객체를 생성하는 것이 아니라 스프링 컨테이너가 객체를 생성한 후 의존성을 주입시켜주는 것을 의미
생성자, 필드, setter로 주입 가능
@Controller
public class Controller{
@Autowired
private Service service;
}setter 주입
@Controller
public class Controller{
private Service service;
@Autowired
public setService(Service service){
this.service = service;
}
}
생성자 주입
@Controller
public class Controller{
private Service service;
@Autowired
public Controller(Service service){
this.service = service;
}
}
장점
참고
https://bestinu.tistory.com/47
https://cheershennah.tistory.com/227
잘 봤습니다. 좋은 글 감사합니다.