@Bean @ConditionalOnMissingBean(GroovyMarkupConfig.class) @ConfigurationProperties(prefix = "spring.groovy.template.configuration") public GroovyMarkupConfigurer groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath(this.properties.getResourceLoaderPath()); configurer.setCacheTemplates(this.properties.isCache()); if (this.templateEngine != null) { configurer.setTemplateEngine(this.templateEngine); } return configurer; }
@Test public void renderTemplate() throws Exception { registerAndRefreshContext(); GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class); MarkupTemplateEngine engine = config.getTemplateEngine(); Writer writer = new StringWriter(); engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile()) .make(new HashMap<String, Object>( Collections.singletonMap("greeting", "Hello World"))) .writeTo(writer); assertThat(writer.toString()).contains("Hello World"); }
@Test public void renderTemplate() throws Exception { registerAndRefreshContext(); GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class); MarkupTemplateEngine engine = config.getTemplateEngine(); Writer writer = new StringWriter(); engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile()) .make(new HashMap<String, Object>( Collections.singletonMap("greeting", "Hello World"))) .writeTo(writer); assertThat(writer.toString(), containsString("Hello World")); }