Я часами искал в Интернете это решение.Я хочу иметь доступ к localhost/index.html
, но не к localhost/layout/style.css
.
Мои статические ресурсы взяты из внешней папки, а дерево файлов выглядит так:
->site
->layout
->style.css
->index.html
Пока чтовсе, что я пробовал, либо отключить доступ к index.html, либо у index и style.css есть доступ.
То, что я нашел в Интернете, имеет смысл:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/*.html").permitAll();
// http.authorizeRequests().antMatchers("/**").permitAll();
super.configure(http);
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/layout/**");
super.configure(web);
}
но когда я использую localhot/layout/style.css
, он показывает файл css.
my WebMvcConfigurerAdapter
:
@Configuration
public class StaticResourceConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("file:mylocation/site/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("redirect:/index.html");
}
}
Аннотации при запуске:
@SpringBootApplication
@EnableWebMvc
public class Main extends SpringBootServletInitializer
Что быбыть в состоянии увидеть index.html, но не все файлы CSS внутри папки макета?
PS: Может быть, это даже невозможно?