In my current spring-boot project, my views have this line:
to reference a static css
I use Spring-Boot 2.0.2
I still keep @EnableWebMvc annotation in my webConfig.java and override addResourceHandlers() method to help browser reaches css and javascript files through http request.
This is the webapp directory's structure
.
webConfig.java
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "example.com")
public class WebConfig implements WebMvcConfigurer {
// =======================================
// = Bean Config =
// =======================================
@Bean
public InternalResourceViewResolver getInternalResourceViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
// =======================================
// = Override Methods =
// =======================================
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pdfs/**")
.addResourceLocations("/WEB-INF/pdfs/");
registry.addResourceHandler("/css/**")
.addResourceLocations("/WEB-INF/css/");
registry.addResourceHandler("/js/**")
.addResourceLocations("/WEB-INF/js/");
}
}
index.jsp head tag:
Title
hope it helps you.