私はSpring Initializrを使用して、埋め込まれたTomcat + Thymeleafテンプレートエンジンを使用してSpringブートWebアプリケーションを生成し、実行可能なJARファイルとしてパッケージ化しました。使用スプリングブート - 春のセキュリティ@ComponentScanまたは@Import
技術:私が持っている
春ブーツ1.4.2.RELEASE、春4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcatの埋め込み8.5.6、Mavenの3、Javaの8
私はアクセスもどここの設定ファイルを使用し、このセキュリティクラスは
com.tdk.config
/**
* @author nunito
* @version 1.0
* @since 4 mar. 2017
*/
@Configuration
@EnableWebSecurity
@PropertySource("classpath:/com/tdk/config/app-${APP-KEY}.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected String loginPage = "/tdk/login";
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage(getLoginPage())
.permitAll()
.and()
.authorizeRequests()
.antMatchers("/mockup/**").permitAll()
.antMatchers("/welcome/**").authenticated()
.and()
.logout()
.permitAll()
.logoutSuccessUrl("/index.html");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.passwordEncoder(new StandardPasswordEncoder())
.withUser("nunito").password("08c461ad70fce6c74e12745931085508ccb2090f2eae3707f6b62089c634ddd2636f380f40109dfb").roles("ADMIN").and()
.withUser("nunito").password("4cfbf05e4493d17125c547fdba494033d7aceee9310f253f3e96c4f928333d2436d669d63a84fe4f").roles("ADMIN");
}
public String getLoginPage() {
return loginPage;
}
public void setLoginPage(String loginPage) {
this.loginPage = loginPage;
}
@SpringBootApplication
@ComponentScan(basePackages = "com.tdk.config")
@EnableAutoConfiguration
public class TdkCloudApplication {
public static void main(String[] args) {
SpringApplication.run(TdkCloudApplication.class, args);
}
}
私は404を持っていますURL内の
しかし、この設定すべてが私にとってまったく同じで
'@EnableWebSecurity'を削除すると、スプリングブートの自動設定が無効になります。スプリングブートとして '@ComponentScan'は必要ありません。すべてのサブパッケージをスキャンします.'EnableAutoConfiguration 'は不要です – Shahbour