spring autowiring not working from a non-spring managed class

前端 未结 10 890
暗喜
暗喜 2020-12-03 06:43

I have a class (Class ABC) that\'s instantiated by calling the constructor. Class ABC in turn has a helper class (Class XYZ) injected using auto-wired.

Ours is a Sp

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 07:32

    In short, yes, ABC is not getting injected with XYZ because Spring is not managing ABC. Spring can't configure objects that it doesn't know about.

    You could manage ABC by annotating it with @Service or @Component. Note that in order for Spring to pick up on these annotations, Spring must have auto-scanning turned on:

    
    

提交回复
热议问题