Could not autowire authentication manager in Spring Boot 2.0.0

Zohaib Khan :

So I've been trying to implement oAuth2 in a simple Spring MVC app.

In the guide I was following, in their AuthorizationServerConfigurerAdapter they @Autowired an AuthenticationManager. They used Spring Boot version 1.5.2.

I wanted to use Spring Boot 2.0.0 as this is the latest version so I wanted to learn the latest practices. However, in my pom.xml when I change:

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

to:

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

All of a sudden, I can't autowire AuthenticationManager.

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

Could someone come up with a solution to this?

Thanks!

erhanasikoglu :

If you want to continue with boot starter packages, according to release notes you need to override authanticationManagerBean method inside the WebSecurityConfigurerAdapter . Here code sample :

@Configuration
@EnableWebSecurity
public static class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=463745&siteId=1