Binding with @Autowired not working inside instances initiated with 'new'

前端 未结 5 1062
谎友^
谎友^ 2021-01-20 08:04

In my web spring application I create an instance with key word new as following.
In my one of action class, following method exists.

publi         


        
5条回答
  •  温柔的废话
    2021-01-20 08:18

    If you want to autowire programmatically, you can use:

    private @Autowired AutowireCapableBeanFactory beanFactory;
    
    public void process() {
       MyBean obj = new MyBean();
       beanFactory.autowireBean(obj);
       // obj will now have its dependencies autowired.
    }
    

提交回复
热议问题