Thymeleaf不热交换Intellij

时间:2015-04-14 16:33:23

标签: java spring intellij-idea thymeleaf jvm-hotspot

我遇到一些问题,使用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("/");
    }
}

到目前为止,这一切都没有奏效。

1 个答案:

答案 0 :(得分:1)

选择部署的爆炸战争。然后,当您点击CMD + F10时,您可以简单地更新资源或类和资源(我假设它可能是Windows / Linux上的CTRL)。