Mohamed Reda Arherbi Mohamed Reda Arherbi - 1 month ago 14
CSS Question

Spring Boot: Adding static content to web application

I'm using Spring Boot and I want to know how exactly we mention the path to static content in my JSP files?
I tried to make them in src/main/resources/static/css but it was not working, and in my JSP I called them by using:



<link href="<c:url value="/css/bootstrap.min.css" />" rel="stylesheet" type="text/css">





I have no special configuration in my SpringBoot Class just the call SpringApplication.run(...)

Thank you so much for the help!

Answer

you have to have configuration that extends WebMvcAutoConfigurationAdapter , it has registry implementation that has automatically scans for some default locations and adds them to classpath

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

Just add,

@Configuration
@EnableWebMvc
@ComponentScan
public class ServerConfiguration extends WebMvcAutoConfiguration{
}   
Comments