【问题标题】:Could not autowire authentication manager in Spring Boot 2.0.0无法在 Spring Boot 2.0.0 中自动装配身份验证管理器
【发布时间】:2018-08-27 03:53:38
【问题描述】:

所以我一直在尝试在一个简单的 Spring MVC 应用程序中实现 oAuth2。

在我关注的指南中,在他们的AuthorizationServerConfigurerAdapter 他们@AutowiredAuthenticationManager。他们使用 Spring Boot 1.5.2 版。

我想使用 Spring Boot 2.0.0,因为这是最新版本,所以我想学习最新的实践。但是,当我更改时,在我的 pom.xml 中:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

到:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

突然之间,我无法自动连接AuthenticationManager

Could not autowire. No beans of 'AuthenticationManager' type found.

有人能想出解决办法吗?

谢谢!

【问题讨论】:

  • 没有可用的解决方案。

标签: java spring-mvc spring-boot spring-security oauth-2.0


【解决方案1】:

如果您想继续使用引导启动程序包,根据release notes,您需要覆盖WebSecurityConfigurerAdapter 内的authanticationManagerBean 方法。 这里的代码示例:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

}

【讨论】:

  • 太棒了!谢谢s2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 2018-10-25
  • 2021-04-21
相关资源
最近更新 更多