Я пытаюсь загрузить Spring Boot 1.4 и Thymeleaf 2. Я хочу защитить свое приложение. Это моя конфигурация безопасности:Spring Boot 1.4 и Thymeleaf 2 Безопасность
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/resources/static/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
Это мой MVC контроллер:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
registry.addViewController("/").setViewName("index");
registry.addViewController("/login").setViewName("login");
}
}
Однако, когда я пытаюсь получить доступ к localhost:8080
он показывает индекс страницы без CSS, JS! Когда я вручную регистрируюсь через localhost:8080/login.html
, все работает нормально. Я подчиняюсь соглашению интеграции Spring и Thymeleaf, а статические ресурсы находятся под /resources/static
и шаблонами под /resource/templates
.
Что такое недостающий пункт для меня?
EDIT:
Он работает с таким образом:
http
.authorizeRequests()
.antMatchers("/css/**").permitAll()
.antMatchers("/js/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
Однако, я должен добавить все папки в статических ресурсов с таким образом? Кажется, я что-то пропустил.
Это странно, но это работает без дополнительной настройки, когда вы помещаете свои файлы css и js в 'src/main/resources/static/resources' – baao