org.springframework.security.core.userdetails.UserDetailsService that could not be found

本文解决了一个常见的SpringBoot项目中整合Spring Security时出现的错误:找不到UserDetailsService类型的服务。通过添加@Service注解,使得自定义的UserDetailServiceImpl类能够被Spring容器正确识别。
摘要由CSDN通过智能技术生成

‘org.springframework.security.core.userdetails.UserDetailsService’ that could not be found

 今天遇见个特别傻的问题,在启动springboot的启动器是出现以下错误
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-12 15:40:29.680 ERROR 6864 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found.

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.


Process finished with exit code 1
这个问题十分简单该实现类没有受到spring的管理 ,来看看 咋的代码
/**
 *  @author: yzy
 *  @Date: 2020/6/12 14:27
 *  @Description: 用户登录认证信息查询
 */

public class UserDetailServiceImpl implements UserDetailsService {

    @Resource
    private IUserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
在该类的上面应该写一个@Service的注解,为什么要加上这个注解呢,因为如果一个类带了@Service注解,该类将
自动注解到spring容器。
/**
 *  @author: yzy
 *  @Date: 2020/6/12 14:27
 *  @Description: 用户登录认证信息查询
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
在启动项目:就好使了

在这里插入代码片

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值