CSS not loading in Spring Boot

前端 未结 8 2155
渐次进展
渐次进展 2020-12-05 00:12

I am new to spring frame work and spring boot.I am trying to add the static html file with CSS,javascript,js. the file structure is

相关标签:
8条回答
  • 2020-12-05 01:16

    I'm new to spring boot too and I have the same problem. I have put the correct path manually into the browser and have seen the 404 by tomcat. Then I have found a solution at: Spring-Boot ResourceLocations not adding the css file resulting in 404

    Now the css file is accessible by code.

    You must move the css folder to src/main/resources/static/css then the content is readable (at my local configuration).

    I hope it works at your configuration too.

    0 讨论(0)
  • 2020-12-05 01:17

    This is what worked for me after many attempts:

    1. css location: /resources/static/css/stylesheet.css
    2. link path in html: th:href="@{/css/stylesheet.css}"
    3. WebSecurityConfig:
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers("/css/**");
      }
      
    0 讨论(0)
提交回复
热议问题