springboot版本從1.5.3升級2.2.x踩坑實錄2--authenticationManager無法注入問題


1. 背景

   在升級springboot版本從1.5.13到2.2.x的過程中出現問題如下

   

 1 ***************************
 2 APPLICATION FAILED TO START
 3 ***************************
 4  
 5 Description:
 6  
 7 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.
 8  
 9 The injection point has the following annotations:
10     - @org.springframework.beans.factory.annotation.Autowired(required=true)
11  
12  
13 Action:
14  
15 Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.

2. 解決方案:

    添加一下配置類WebSecurityConfig,代碼如下:

/**
 * @Auther: duke
 * @Date: 2018-11-23 10:36
 * @Description:要求用戶在進入你的應用的任何URL之前都進行驗證
 */
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
 
    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
    //.......
    //要求用戶在進入你的應用的任何URL之前都進行驗證
    //創建一個用戶名是“user”,密碼是“password”,角色是“ROLE_USER”的用戶
    //啟用HTTP Basic和基於表單的驗證
    //Spring Security將會自動生成一個登陸頁面和登出成功頁面
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM