How to autowire an object in spring in an object created with new

前端 未结 5 2062
广开言路
广开言路 2021-02-07 12:35

all I want to do is autowire the field backgroundGray in the NotesPanel class, but all I get is the exception below.

So, question is, how to autowire it correctly ? It r

5条回答
  •  情深已故
    2021-02-07 13:10

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

    as workaround you can try this:

    create your template bean of NotesPanel

    
        
    
    

    and create an istance in this way

    context.getBean("notesPanel");
    

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

提交回复
热议问题