Netbeans 8不会重新加载静态Thymeleaf文件 [英] Netbeans 8 won't reload static Thymeleaf files

查看:89
本文介绍了Netbeans 8不会重新加载静态Thymeleaf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Maven使用Spring Boot和Thymeleaf.进行更改时,似乎无法让Netbeans自动重新部署任何Thymeleaf模板文件.为了查看更改,我需要进行完整的清理/构建/运行.这花费了太长时间.

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.

模板在src/main/resources/templates中.我在src/main/resources/中有一个spring.thymeleaf.cache=falsespring.template.cache=false的application.properties文件.

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.

我的maven版本生成一个war文件,Netbeans将该文件部署到Tomcat,并且我正在使用注释@EnableAutoConfiguration.

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

Netbeans 确实对Java类进行热部署更改,但不对src/main/resources/中的任何静态文件进行更改.

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

正在使用的软件:

  • 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(通过Spring Boot)

非常感谢任何指导.

推荐答案

一种选择是考虑配置Thymeleaf的

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

要使用Spring Boot做到这一点,请定义一个实现ITemplateResolver接口且名称为defaultTemplateResolver的bean,当存在时,Spring Boot将采用它而不是默认值,这是完成操作的方法,并假设您启用了组件扫描功能,因此将自动获取此配置类:

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;
  }
}

prefix应该是一个相对路径,当添加到运行时工作目录(cwd)时,它将解析为模板目录.如果不确定,请将其设置为完整的绝对路径,但是上面的bean没有意义.由于将spring.thymeleaf.prefix属性设置为绝对路径可能会产生相同的效果.

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.

这篇关于Netbeans 8不会重新加载静态Thymeleaf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆