@Autowired object gets a null value in one class, while successfully wired in another

前端 未结 5 1638
无人共我
无人共我 2021-02-19 01:23

I am working on a project using Spring 3, and Spring Security. My problem is with IoC container. Problem started when I wrote my own implementation of UserDetailsService

5条回答
  •  北海茫月
    2021-02-19 01:49

    I had the same problem. Although this can happen in many ways, in my case I was creating a new object, instead of using the autowired one. i.e.:

    private Service service = new ServiceImpl();
    

    instead of:

    @Autowired private Service service;
    

    This was not in the Service using the Repository injection, but in a controller on top of that.

提交回复
热议问题