1.のpom.xmlには依存に参加します
<! -加入密码认证- > <依存> <groupIdを> org.springframework.boot </ groupIdを> <たartifactId>春・ブート・スターター・セキュリティ</たartifactId> </依存関係>
2. application.propertiesの設定ユーザ名とパスワードを次のようです
#有効にセキュアな認証のユーザ名とパスワードspring.security.basic.enabled = truespring.security.user.name = adminspring.security.user.password =ルート
3. [追加設定クラスWebSecurityConfig.java
パッケージorg.fh.config;輸入org.springframework.security.config.annotation.web.builders.HttpSecurity;輸入org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;輸入org.springframework.security.config。 annotation.web.configuration.WebSecurityConfigurerAdapter;輸入org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; / ** *说明:CSRF保护禁用 *作者:www.1b23.com * / EnableWebSecuritypublicクラスWebSecurityConfig @ WebSecurityConfigurerAdapter {拡張 @Override 保護を空configureは(HttpSecurity HTTP)例外{スロー SavedRequestAwareAuthenticationSuccessHandler successHandler =新しいSavedRequestAwareAuthenticationSuccessHandler()。 successHandler.setTargetUrlParameter( "redirectToを"); http.headers()frameOptions()無効()。。。 http.csrf()無効()authorizeRequests()( "/アクチュエータ/ **")permitAll()antMatchers anyRequest()認証()および()httpBasic()。。。。。。。。。 } }