@Autowired return exception on UserDetails in Spring-security

后端 未结 1 1848
梦毁少年i
梦毁少年i 2021-01-03 21:52

Please show me where I have problem? Here is my project: https://github.com/intrade/inventory I try to enable Spring security using java config and when I try to inject a de

相关标签:
1条回答
  • 2021-01-03 22:06

    You are trying to autowire your user details service by class, but that can't work, because the spring bean is actually a proxy created around that class (and not an instance of the class). The proxy will however implement all interfaces of the original bean, so injecting by interface is safe.

    Exchange this line:

    @Autowired
    private MyCustomUserDetailsService myCustomUserDetailsService;
    

    for this one:

    @Autowired
    private UserDetailsService myCustomUserDetailsService;
    

    Read the section on Proxying Mechanisms in the Spring AOP to understand the details.

    0 讨论(0)
提交回复
热议问题