关于SpringSecurity配置文件中自定义userDetailsService报错
报错:
Field userDetailsService in com.zhao.security.config.WebSecurityConfig required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
The following candidates were found but could not be injected:
- Bean method 'inMemoryUserDetailsManager' in 'UserDetailsServiceAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationManager,org.springframework.security.authentication.AuthenticationProvider,org.springframework.security.core.userdetails.UserDetailsService,org.springframework.security.oauth2.jwt.JwtDecoder,org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector; SearchStrategy: all) found beans of type 'org.springframework.security.authentication.AuthenticationManager' authenticationManager
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration.
原因:
自定义业务对象,但是引入的是org.springframework.security.core.userdetails.中的userDetailsService。导致找不到userDetailsService。
办法1:(不保留自定义)取消自定义对象类,在自定义对象类实现方法中直接导入官方的对象类
办法2:(保留自定义)在自己写的自定义对象类中继承官方的对象类