Repository injection dependency. Method 1 can obtain dependencies normally. The dependency acquired by method 2 is null
1.In UserInfoRepository I used the constructor to inject userInfoMapper:
-
UserInfoMapper is normal when I call selectList:
-
But it was null when I called another method
-
Change @ Repository to @ Service and it will work normally. Shouldn't Repository and Service be working properly?
Comment From: wilkinsona
Questions like this don't really belong here for a couple of reasons I'm afraid. First, we prefer to use the issue tracker for bugs and enhancements and this looks like a usage question. Second, the functionality that you're asking about is provided by Spring Framework.
With that said, @Repository and @Service are both annotated with @Component so they should behave in the same way from a dependency injection perspective. Spring Framework won't inject null into a constructor so I would guess that, in the case where it doesn't work, something else has created the instance.
If you need some help figuring out why that's happening, please follow up on Stack Overflow and include in your question everything that's necessary to reproduce the problem. That should be in the form of text rather than screenshots. Ideally, the question would link to a GitHub repository that contains all of the necessary code.