0

I know that there are similar questions on this subject, but I can't seem to find a solution. I have a Spring MVC project and the problem is that I get the error specified in the title in the browser log when I run the app. If I open the index.html in browse (not from Spring) the CSS is loaded.

This is my structure.

index.html CSS declaration

    <link rel="stylesheet" type="text/css" th:href="@{ /css/index.css }"
          href="../../resources/static/css/index.css">

Controller

@RequestMapping(value = { "/", "/index"}, method = RequestMethod.GET)
public ModelAndView index() {
    ModelAndView model = new ModelAndView();
    model.setViewName("index");

    return model;
}

I even tried to add this in the SecurityConfiguration

@Override
public void configure(WebSecurity web) throws Exception {
    super.configure(web);

    web.ignoring().antMatchers("/resources/**", "/static/**", "/css/**", "/icons/**", "/javascript/**");

}

but it doesn't work.

The path is good because as I said when I open the index.html in browser the CSS is loaded, I think that the problem is with the SecurityConfiguration class, but I don't know what it is.

Does anyone have any idea?

sao
  • 1,835
  • 6
  • 21
  • 40

1 Answers1

1

So the error was indeed from SecurityConfiguration because I wasn't using the right annotation. The correct one is

@EnableWebSecurity

and I was using

@EnableWebMvc

So now my class looks like this:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired
private DataSource dataSource;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

}

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable();

    http.authorizeRequests().antMatchers("/", "/index").permitAll().and()
            .exceptionHandling().accessDeniedPage("/libraryAppError");
    http.authorizeRequests().antMatchers("/resources/**").permitAll().anyRequest().permitAll();
}
}

And everything works fine.