title: spring security doesn't load the resources (images, css)
body: <p>I'm new to spring security, and I try to implement an athorisation in my project. Everything work's fine, but the images and css files are not loaded. I'm using the (annotations) way to configure it.</p>
  
  <p>Here is my project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/fY3N7.png" alt="project structure"></p>
  
  <p>The configuration of resource mapping in dispatcher spring-web-servlet: </p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/views/jsp/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  </code></pre>
  
  <p>My web.xml</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;spring-web&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring-web&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;error-page&gt;
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/WEB-INF/views/errors/error404.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  
  &lt;filter&gt;
  &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
  &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy
              &lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>Spring Security configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
  
      @Autowired
      @Qualifier("userDetailsService")
      UserDetailsService userDetailsService;
  
      @Autowired
      PersistentTokenRepository tokenRepository;
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
              auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
        http.authorizeRequests()
  
              .antMatchers("/").permitAll()
              .antMatchers("/resources/**").permitAll() .anyRequest().permitAll()
              .antMatchers("/*.css","/*.jpg").permitAll().anyRequest().permitAll()
              .antMatchers("/css/**", "/js/**","/img/**", "/webjars/**", "**/favicon.ico", "/index").permitAll().anyRequest().permitAll()
              .antMatchers("/login").permitAll()
              .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
              .antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')")
              .antMatchers("/users/**").access("hasRole('ROLE_USER')")
              .and()
              .formLogin().loginPage("/login").failureUrl("/login?error")
              .usernameParameter("username").passwordParameter("password")
              .loginProcessingUrl("/j_spring_security_check")
              .defaultSuccessUrl("/users/users_page")
                  .and()
              .logout().logoutUrl("/j_spring_security_logout").logoutSuccessUrl("/login?logout")
                  .and()
              .rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository).tokenValiditySeconds(86400)
                  .and()
              .csrf().disable();
  
      }
  
      @Bean
      public PasswordEncoder passwordEncoder(){
              PasswordEncoder encoder = new BCryptPasswordEncoder();
              return encoder;
      }
  
      @Bean
      public PersistentTokenBasedRememberMeServices getPersistentTokenBasedRememberMeServices() {
          PersistentTokenBasedRememberMeServices tokenBasedservice = new PersistentTokenBasedRememberMeServices(
                  "remember-me", userDetailsService, tokenRepository);
          return tokenBasedservice;
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers("/*.css");
          web.ignoring().antMatchers("/*.jpg");
      }
  }
  </code></pre>
  
  <p>I'm trying to load the css file like this:</p>
  
  <pre><code> &lt;link rel="stylesheet" type="text/css" 
         href="&lt;c:url value="${pageContext.request.contextPath}/resources/static/css/test_style.css"/&gt;"
  </code></pre>
  
  <p>and the images like this:</p>
  
  <pre><code>&lt;img src="&lt;c:url value='/resources/static/img/head.jpg' /&gt;" type="image/jpg"  alt="BigLogo" height="650"  width="1000"/&gt; 
  </code></pre>
  
  <p>As a result, the images are not displayed, and the css files are getting error:</p>
  
  <pre><code>Refused to apply style from '&lt;URL&gt;' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. 
  </code></pre>
  
  <p>What am I doing wrong?
  Are there some configuration problems?
  I searched a lot, but I didn't find some solutions that can help me.
  I will be very thankful for your help.</p>