Spring 자체 인스턴스화 된 객체에 종속성을 주입하는 방법
private @Autowired AutowireCapableBeanFactory beanFactory;
public void doStuff() {
MyBean obj = new MyBean();
beanFactory.autowireBean(obj);
// obj will now have its dependencies autowired.
}
- AutowireCapableBeanFactory의 autowireBean을 이용하여 자체 인스턴스화 된 객체에 종속성을 주입을 할수가 있다.
직접 ApplicationContext를 접근해서 하는 방법 방법
AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
factory.autowireBean(obj);
'Programing > Spring Framework' 카테고리의 다른 글
Spring Web MVC Filter, Interceptor (0) | 2018.12.14 |
---|---|
Spring Retry (0) | 2018.10.30 |
Spring Bean Life Cycle (0) | 2018.09.21 |
Spring @Transactional Propagation (0) | 2018.09.10 |
Spring Constructor Dependency Injection (0) | 2018.09.06 |