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

前端 未结 5 1109
小鲜肉
小鲜肉 2021-02-19 01:32

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:47

    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.

提交回复
热议问题