field authenticationmanager需要类型为“org.springframework.security.authentication.authenticationmanager”的bean

8ulbf1ek  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(571)

我是springboot的新手,尝试实现我从这个链接中学到的东西:登录注册特性。我的目标是建立一个用户登录和注册功能,但我遇到了这个错误:


***************************

APPLICATION FAILED TO START

***************************

Description:

Field authenticationManager in com.x.assignment.auth.service.SecurityServiceImpl required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.

我的文件夹结构,代码与链接中提到的相同。但不明白为什么@autowired不起作用。请帮帮我。谢谢您。

8fq7wneg

8fq7wneg1#

在配置类中 WebSecurityConfig 直接添加bean:

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

相关问题