# thymeleaf热部署 spring.thymeleaf.cache=false
@Value("${spring.thymeleaf.cache}")
private boolean thymeleafCacheEnable = true;
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/** * 模板资源解析器 * @return */ @Bean @ConfigurationProperties(prefix = "spring.thymeleaf") public SpringResourceTemplateResolver templateResolver() { SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(this.applicationContext); templateResolver.setCharacterEncoding("UTF-8"); templateResolver.setCacheable(thymeleafCacheEnable); return templateResolver; } /** * Thymeleaf标准方言解释器 */ @Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); // 支持Spring EL表达式 templateEngine.setEnableSpringELCompiler(true); // 支持SpringSecurity方言 SpringSecurityDialect securityDialect = new SpringSecurityDialect(); templateEngine.addDialect(securityDialect); return templateEngine; } /** * 视图解析器 */ @Bean public ThymeleafViewResolver viewResolver() { ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); return viewResolver; }