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

前端 未结 5 2071
广开言路
广开言路 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:14

    Spring support @Autowire, ... only for Spring Beans. Normally a Java Class become a Spring Bean when it is created by Spring, but not by new.

    One workarround is to annotate the class with @Configurable but you must use AspectJ (compile time or loadtime waving)!

    @see Using Spring's @Configurable in three easy steps for an short step by step instruction.

提交回复
热议问题