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

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

    When you create an object by new, autowire\inject don't work...

    as workaround you can try this:

    create your template bean of MyBean

    
        
    
    

    and create an istance in this way

    context.getBean("myBean");
    

    PROTOTYPE : This scopes a single bean definition to have any number of object instances.

提交回复
热议问题