This is the the picture of my project. I have my css file in static/css folder and I am trying to link it with my index.jsp page but it's not working. NB : Hard refresh, cache clear everything is done and I have tried more than 10 times. :( is there any other way to link up css with spring boot application?
-
Place your static folder under resources folder – SAP Apr 11 '17 at 01:56
3 Answers
In the Spring-boot documentation you can read where Spring-boot reads static resources by default.
By default Spring Boot will serve static content from a directory called
/static (or /public or /resources or /META-INF/resources)
in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHandler from Spring MVC so you can modify that behavior by adding your own WebMvcConfigurerAdapter and overriding the addResourceHandlers method.
If you change the location of your static files to the default one you should be able to reach them by /css/style.css

- 12,336
- 15
- 73
- 115
-
Hi, Thanks for the answer. I have tried it by putting static folder inside of my src/main/resources directory and was trying to link the css like /css/style.css and still not working.!! :( – user2817233 Apr 11 '17 at 11:16
-
@user2817233 can you describe more in your question what is not working. Can you also show the network tab of your browser. There we can see the http status of css file. – Patrick Apr 11 '17 at 11:25
For me now I just put my CSS, JS, images in src/main/resources/static folder and the link is like :
/css/style.css
or /js/custom.js
is working fine for spring boot application.

- 4,451
- 7
- 35
- 47

- 23
- 1
- 5
The solution to your problem is very simple, just add to your application.properties file (your configuration file) the next 2 lines of code:
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
this will bust the cache in your browser, and when you'll make changes regarding to static content (like: css files, js files, html files), it will take place.
Spring Boot CSS Showing up blank / not loading after trying everything
Good Luck.

- 1
- 1

- 3,587
- 4
- 18
- 33