Thymeleaf can not find resources

2

I am creating a project with Springboot and Thymeleaf . I have set up the whole project, found the template and the pages, so my template can not find the css and js

Html

<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}"/>

application.properties

# --- CONFIGURAÇÃO TYMELEAF ---
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
spring.thymeleaf.content-type=text/html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.enabled=true

WebMvcConfigurerAdapter

@Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
             registry.addResourceHandler("/resources/**")
                     .addResourceLocations("/resources/")
                     .addResourceLocations("/static/")
                     .addResourceLocations("/static/**")
                     .addResourceLocations("/resources/static/")
                     .addResourceLocations("/resources/static/**")
                     .addResourceLocations("/")
                     .addResourceLocations("/**");
     }

Folder structure

    
asked by anonymous 19.12.2016 / 00:22

1 answer

3

If you are using spring boot, then it simplifies things for you and automatically leaves external access to the / static folder, as well as others according to the documentation.

  

While this may not be a new revelation to those of you that have been following Spring Boot since the SpringOne announcement, there is one detail for which you may not be aware. Spring Boot will automatically add static web resources located within any of the following directories:

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

Spring Boot Documentation

Inside the src / main / resources / static /: folder

<script src="/bootstrap/js/bootstrap.js" th:src="@{/bootstrap/js/bootstrap.js}"></script>

<link href="/bootstrap/css/bootstrap.css" th:href="@{/bootstrap/css/bootstrap.css}" rel="stylesheet"  />
    
06.01.2017 / 07:47