/** * Register a Groovy markup view resolver with an empty default view name * prefix and a default suffix of ".tpl". */ public UrlBasedViewResolverRegistration groovy() { if (this.applicationContext != null && !hasBeanOfType(GroovyMarkupConfigurer.class)) { throw new BeanInitializationException("In addition to a Groovy markup view resolver " + "there must also be a single GroovyMarkupConfig bean in this web application context " + "(or its parent): GroovyMarkupConfigurer is the usual implementation. " + "This bean may be given any name."); } GroovyMarkupRegistration registration = new GroovyMarkupRegistration(); this.viewResolvers.add(registration.getViewResolver()); return registration; }
@Before public void setUp() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); context.registerSingleton("velocityConfigurer", VelocityConfigurer.class); context.registerSingleton("tilesConfigurer", TilesConfigurer.class); context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class); context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class); this.registry = new ViewResolverRegistry(); this.registry.setApplicationContext(context); this.registry.setContentNegotiationManager(new ContentNegotiationManager()); }
@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 customConfiguration() throws Exception { registerAndRefreshContext( "spring.groovy.template.configuration.auto-indent:true"); assertThat(this.context.getBean(GroovyMarkupConfigurer.class).isAutoIndent()) .isEqualTo(true); }
@Test public void customConfiguration() throws Exception { registerAndRefreshContext( "spring.groovy.template.configuration.auto-indent:true"); assertThat(this.context.getBean(GroovyMarkupConfigurer.class).isAutoIndent(), is(true)); }
@Bean public GroovyMarkupConfigurer groovyMarkupConfigurer() { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath("/WEB-INF/"); return configurer; }