Thymeleaf does not find Sources

Asked

Viewed 1,612 times

2

I’m creating a project with Springboot and Thymeleaf. I set up the whole project, I find the template and the pages, so my template can’t find the files 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

inserir a descrição da imagem aqui

1 answer

3


If you are using spring boot, then it simplifies things for you and already 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"  />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.