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將會自動生成一個登陸頁面和登出成功頁面 }