java - Thymeleaf 不热插拔 Intellij

标签 java spring intellij-idea thymeleaf jvm-hotspot

我在使用 Intellij 进行 Thymeleaf 模板热插拔/更新时遇到一些问题。目前我必须重新启动整个服务器才能看到我的更改,这相当乏味并且减慢了我的工作流程。

我正在使用 Gradle、Intellij 14.1 和 Tomcat 8。我正在 Debug模式下运行应用程序。

我尝试将 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("/");
    }
}

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

最佳答案

选择爆炸 war 进行部署。然后,当您点击 CMD + F10(我认为在 Windows/Linux 上可能是 CTRL)时,您可以简单地更新资源或类和资源。

关于java - Thymeleaf 不热插拔 Intellij,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632720/

相关文章:

java - 代码验证错误

java - FirstCup JavaEE 教程的问题

java - Intellij 资源不在内置工件中

java - 添加 servlet 或过滤器时,web.xml intellij 不会自动完成

maven - IntelliJ IDEA 中有 Maven 插件,无需在计算机上安装 Maven

java - 从类路径上的类开始运行 Java 程序

java - 是否有理由使用字符串 => 索引到 vector 的映射,而不是字符串 => 对象?

spring - 使用spring3检测 session 过期或 session 超时

spring - 无法调用 "java.lang.Object.hashCode()",因为 "value"为空

Spring Controller ,为什么返回的 View 被忽略了?