Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans 8 won't reload static Thymeleaf files

I am using Spring Boot and Thymeleaf via Maven. I can't seem to get Netbeans to automatically re-deploy any of my Thymeleaf template files when I make changes. In order to see the changes I need to do a full clean/build/run. This takes way too long.

The templates are in src/main/resources/templates. I have an application.properties file in src/main/resources/ with spring.thymeleaf.cache=false and spring.template.cache=false.

I have "Compile on save", "Copy resources on save" and "Deploy on save" turned on in the project settings.

My maven build produces a war file that Netbeans deploys to Tomcat and I am using the annotation @EnableAutoConfiguration.

Netbeans does hot deploy changes to the Java classes but not for any of the static files in src/main/resources/.

Software in use:

  • Mac OS X 10.9.4
  • Java 1.8
  • Netbeans 8.0.1
  • Tomcat 8.0.12
  • Spring Boot 1.1.7
  • Thymeleaf 2.1.3 (via Spring Boot)

Any guidance is much appreciated.

like image 594
Hamish Avatar asked Feb 11 '23 22:02

Hamish


1 Answers

An option would be to look into configuring Thymeleaf's FileTemplateResolver

To do that with Spring Boot, define a bean implementing the ITemplateResolver interface with the name defaultTemplateResolver, when present, Spring Boot would take it instead of its default, here is how that would be done, and assuming you have component scanning active so this configuration class will be picked up automatically:

@Configuration
public class ThymeleafConfiguration {
  @Bean
  public ITemplateResolver defaultTemplateResolver() {
    TemplateResolver resolver = new FileTemplateResolver();
    resolver.setSuffix(".html");
    resolver.setPrefix("path/to/your/templates");
    resolver.setTemplateMode("HTML5");
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCacheable(false);
    return resolver;
  }
}

The prefix should be a relative path that when added to your runtime working directory (cwd), would resolve to the templates directory. If you are unsure, set that to the full absolute path, but then there would be no point of the above bean. Since setting the spring.thymeleaf.prefix property to an absolute path would probably have the same effect.

like image 105
Amr Mostafa Avatar answered Feb 15 '23 00:02

Amr Mostafa