Jtwig Hot Reloading Extension
How to use?
- Include the dependency in your project (check bintray).
- Add to your custom Jtwig configuration
EnvironmentConfiguration configuration = EnvironmentConfigurationBuilder
.configuration()
.extensions()
.add(new HotReloadingExtension(TimeUnit.SECONDS, 1))
.and()
.build();
How it works?
- If the referenced resource is a file, it then checks for the last modified date and depending on such date, this may evict the cached template.
Integration with Spring Boot
Note that, jtwig-spring-boot-started module, by default, sets the template source as the classpath, bundling such application inside a standalone jar makes it impossible to edit such template files. For this to work, an easy solution can be to use templates stored in a specific directory, as shown in the example below:
@Configuration
public class JtwigConfig implements JtwigViewResolverConfigurer {
@Override
public void configure(JtwigViewResolver viewResolver) {
viewResolver.setPrefix("file:/path/to/base/directory");
viewResolver.setRenderer(new JtwigRenderer(EnvironmentConfigurationBuilder
.configuration()
.extensions().add(new HotReloadingExtension(TimeUnit.SECONDS, 1)).and()
.build()));
}
}
Build Stats
Licensing
Requirements
- Java 7