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

前端 未结 5 1065
谎友^
谎友^ 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:10

    In your case, spring does not recognize MyBean bean because you are creating it with new operator. Let spring initialize this bean and then you can have autowired beans accessed inside MyBean. For e.g.

    
    

    Above entry in your application context will create MyBean in spring container. And using this object you can access the services written inside it.

提交回复
热议问题