【SpringBoot】浏览器报错Resource interpreted as Stylesheet but transferred with MIME type text/html
生活随笔
收集整理的這篇文章主要介紹了
【SpringBoot】浏览器报错Resource interpreted as Stylesheet but transferred with MIME type text/html
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
CSS 樣式不能正常加載
發(fā)現頁面的樣式沒有顯示,報錯信息如下:
Resource interpreted as Stylesheet but transferred with MIME type text/html: “http://localhost:8080/curd/asserts/css/signin.css”.
原因
之前寫原生 jsp + servlet 的時候也遇到過這個問題,當時是因為Filter過濾器。原文:
【JavaWeb】已解決:Resource interpreted as Stylesheet but transferred with MIME type text/html
這次用 SpringBoot 又遇到了同樣的問題,所以直接猜測,是因為添加了Intercepter攔截器。
解決方式
在addinterceptors方法 excludePathPatterns中排除了項目的資源路徑,重啟項目,OK,效果圖:
附,攔截器代碼:
原有攔截器:
//所有的WebMvcConfigureAdapter組件會一起起作用@Bean//將組件注冊在容器@SuppressWarnings("all")public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/index.html").setViewName("login");registry.addViewController("/main.html").setViewName("dashboard");}//注冊攔截器@Overridepublic void addInterceptors(InterceptorRegistry registry) { // super.addInterceptors(registry);//攔截所有,手動放行部分//靜態(tài)資源不需要處理,可以正常訪問。springboot已經做好了靜態(tài)資源映射registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html","/","/user/login");}};return adapter;}修改后:
//所有的WebMvcConfigureAdapter組件會一起起作用@Bean//將組件注冊在容器@SuppressWarnings("all")public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/index.html").setViewName("login");registry.addViewController("/main.html").setViewName("dashboard");}//注冊攔截器@Overridepublic void addInterceptors(InterceptorRegistry registry) { // super.addInterceptors(registry);//攔截所有,手動放行部分//靜態(tài)資源不需要處理,可以正常訪問。springboot已經做好了靜態(tài)資源映射registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/","login","/login", "/login.html", "/user/login", "/**/*.css", "/**/*.js", "/**/*.png","/**/*.jpg","/**/*.jpeg", "/**/*.gif", "/**/fonts/*", "/**/*.svg","/**/*.ico","/**/*.map");}};return adapter;}總結
以上是生活随笔為你收集整理的【SpringBoot】浏览器报错Resource interpreted as Stylesheet but transferred with MIME type text/html的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【SpringBoot】SpringBo
- 下一篇: 【SpringBoot】添加自定义浏览器