1. 程式人生 > >【Spring Boot問題】--authenticationManager無法注入

【Spring Boot問題】--authenticationManager無法注入

在更換spring-boot-auto-config的版本從1.5.13升級至2.0.6的過程中出現問題

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
      <scope>provided</scope>
</dependency>

問題描述如下:

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

Description:

Field configurers in org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration 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.

在網上參考的做法:

authenticationManager無法注入問題

authenticationManager 無法注入解決辦法

我自己的解決辦法是,新增一下配置類WebSecurityConfig

/**
 * @Auther: chisj [email protected]
 * @Date: 2018-11-23 10:36
 * @Description:
 */
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

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

啟動後,問題解決