Thymeleaf 不热插拔 Intellij
Thymeleaf Not Hot Swapping Intellij
我在使用 Intellij 对 Thymeleaf 模板进行热插拔/更新时遇到了一些问题。目前我必须完全重启服务器才能看到我的更改,这相当乏味并且会减慢我的工作流程。
我正在使用 Gradle、Intellij 14.1 和 Tomcat 8。我 运行 应用程序处于调试模式。
我试过将 Thymeleaf 设置为不可缓存。
@Configuration
public class ThymeleafConfig {
@Autowired
Environment environment;
@Bean
public ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix(environment.getRequiredProperty("thymeleaf.resolver.prefix"));
resolver.setSuffix(environment.getRequiredProperty("thymeleaf.resolver.suffix"));
resolver.setTemplateMode(environment.getRequiredProperty("thymeleaf.resolver.templatemode"));
resolver.setOrder(environment.getRequiredProperty("thymeleaf.resolver.order", Integer.class));
resolver.setCacheable(environment.getRequiredProperty("thymeleaf.resolver.cacheable", Boolean.class));
resolver.setCharacterEncoding(environment.getRequiredProperty("thymeleaf.resolver.character.encoding"));
return resolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(templateResolver());
engine.addDialect(new LayoutDialect());
engine.addDialect(new SpringSecurityDialect());
return engine;
}
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
return resolver;
}
}
属性 上述代码从中读取的文件。
# Thymeleaf
thymeleaf.resolver.prefix=/WEB-INF/views/
thymeleaf.resolver.suffix=.html
thymeleaf.resolver.templatemode=HTML5
thymeleaf.resolver.order=1
thymeleaf.resolver.cacheable=false
thymeleaf.resolver.character.encoding=UTF-8
我也尝试在 ApplicationInitializer 中设置它。
@Override
public void onStartup(ServletContext container) throws ServletException {
/**
* If no active profile is set via -Dspring.profiles.active then the application
* will default to development mode
*/
container.setInitParameter("spring.profiles.default", "dev");
/**
* Set thymeleaf cache to false if -Dspring.thymeleaf.cache is not passed
*/
container.setInitParameter("spring.thymeleaf.cache", "false");
/**
* create the root Spring application context
*/
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setDisplayName("app");
rootContext.register(AppConfig.class);
/**
* manage the lifecycle of the root application context
*/
container.addListener(new ContextLoaderListener(rootContext));
/**
* register and map the dispatcher servlet
*/
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
到目前为止 none 已经奏效了。
Select 为部署展开 war。然后您可以在按下 CMD + F10 时简单地更新资源或 类 和资源(我假设它可能是 Windows/Linux 上的 CTRL)。
我在使用 Intellij 对 Thymeleaf 模板进行热插拔/更新时遇到了一些问题。目前我必须完全重启服务器才能看到我的更改,这相当乏味并且会减慢我的工作流程。
我正在使用 Gradle、Intellij 14.1 和 Tomcat 8。我 运行 应用程序处于调试模式。
我试过将 Thymeleaf 设置为不可缓存。
@Configuration
public class ThymeleafConfig {
@Autowired
Environment environment;
@Bean
public ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix(environment.getRequiredProperty("thymeleaf.resolver.prefix"));
resolver.setSuffix(environment.getRequiredProperty("thymeleaf.resolver.suffix"));
resolver.setTemplateMode(environment.getRequiredProperty("thymeleaf.resolver.templatemode"));
resolver.setOrder(environment.getRequiredProperty("thymeleaf.resolver.order", Integer.class));
resolver.setCacheable(environment.getRequiredProperty("thymeleaf.resolver.cacheable", Boolean.class));
resolver.setCharacterEncoding(environment.getRequiredProperty("thymeleaf.resolver.character.encoding"));
return resolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(templateResolver());
engine.addDialect(new LayoutDialect());
engine.addDialect(new SpringSecurityDialect());
return engine;
}
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
return resolver;
}
}
属性 上述代码从中读取的文件。
# Thymeleaf
thymeleaf.resolver.prefix=/WEB-INF/views/
thymeleaf.resolver.suffix=.html
thymeleaf.resolver.templatemode=HTML5
thymeleaf.resolver.order=1
thymeleaf.resolver.cacheable=false
thymeleaf.resolver.character.encoding=UTF-8
我也尝试在 ApplicationInitializer 中设置它。
@Override
public void onStartup(ServletContext container) throws ServletException {
/**
* If no active profile is set via -Dspring.profiles.active then the application
* will default to development mode
*/
container.setInitParameter("spring.profiles.default", "dev");
/**
* Set thymeleaf cache to false if -Dspring.thymeleaf.cache is not passed
*/
container.setInitParameter("spring.thymeleaf.cache", "false");
/**
* create the root Spring application context
*/
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setDisplayName("app");
rootContext.register(AppConfig.class);
/**
* manage the lifecycle of the root application context
*/
container.addListener(new ContextLoaderListener(rootContext));
/**
* register and map the dispatcher servlet
*/
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
到目前为止 none 已经奏效了。
Select 为部署展开 war。然后您可以在按下 CMD + F10 时简单地更新资源或 类 和资源(我假设它可能是 Windows/Linux 上的 CTRL)。