Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro com CSS e JS

Ao ativar o Spring Security e configura-lo corretamente (ele funciona certinho, broqueando as páginas que quero que bloqueie, liberando as que quero que libere) minha aplicação não consegue mais acessar os arquivos css, deixando a página totalmente sem formatação. Ao entrar no console do Chrome o seguinte erro é apresentado, 10 vezes:

Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Em resumo o erro é o mesmo para todos, tentei no método Configure() do SecurityConfiguration liberar o caminho "/resources/**" mas mesmo assim o problema continua.

meu SecurityConfiguration:

package br.com.casadocodigo.loja.conf;

import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/produtos/form").hasRole("ADMIN") //o melhor é bloquear tudo, depois liberar o que quer
            .antMatchers("/carrinho").permitAll()
            .antMatchers(HttpMethod.POST,"/produtos").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET,"/produtos").hasRole("ADMIN")
            .antMatchers("/resources/**").permitAll()
            .antMatchers("/css/**").permitAll()
            .antMatchers("/fonts/**").permitAll()
            .antMatchers("/js/**").permitAll()
            .antMatchers("/produtos/**").permitAll()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated()
            .and().formLogin();

    }

}
2 respostas

De forma mais específica ele apresenta também os URLs que está tentando acessar:

Refused to apply style from 'http://localhost:8080/casadocodigo/produtos/detalhe/resources/css/cssbase-min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/fontello-ie7.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/fonts.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/fontello.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/layout-colors.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/fontello-embedded.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/responsive-style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/produtos.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
18:1 Refused to apply style from 'http://localhost:8080/casadocodigo/resources/css/guia-do-programador-style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
solução!

Enquanto escrevia esse post me deu um clique, e lembrei que havia apagado todos os Resources e colocado apenas os do bootstrap, no fim ele não estava encontrando alguns dos css e acabou não pegando nenhum. Quando recoloquei a pasta Resources completa que peguei na Atividade 01 funcionou certinho.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software