@Bean public VelocityConfig velocityConfig() throws IOException, VelocityException { Properties config = new Properties(); config.setProperty("input.encoding", "UTF-8"); config.setProperty("output.encoding", "UTF-8"); config.setProperty("default.contentType", "text/html;charset=UTF-8"); config.setProperty("resource.loader", "class"); config.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); VelocityConfigurer velocityConfigurer = new VelocityConfigurer(); velocityConfigurer.setVelocityProperties(config); velocityConfigurer.afterPropertiesSet(); return velocityConfigurer; }
@Bean @ConditionalOnMissingBean(VelocityConfig.class) public VelocityConfigurer velocityConfigurer() { VelocityConfigurer configurer = new VelocityConfigurer(); applyProperties(configurer); return configurer; }
@Bean public VelocityConfig velocityConfig() { Properties p = new Properties(); p.put( "resource.loader", "webapp" ); p.put( "webapp.resource.loader.path", new File( webapp, "html" ).toString() ); p.put( "webapp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader" ); VelocityConfigurer vc = new VelocityConfigurer(); VelocityEngine engine = new VelocityEngine( p ); engine.init(); vc.setVelocityEngine( engine ); return vc; }
/** * Autodetect a VelocityEngine via the ApplicationContext. Called if no * explicit VelocityEngine has been specified. * * @return the VelocityEngine to use for VelocityViews * @throws BeansException * if no VelocityEngine could be found * @see #getApplicationContext * @see #setVelocityEngine */ protected VelocityEngine autodetectVelocityEngine() throws BeansException { try { VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(), VelocityConfig.class, true, false); return velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application context " + "(may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } }
/** * Autodetect a VelocityEngine via the ApplicationContext. * Called if no explicit VelocityEngine has been specified. * @return the VelocityEngine to use for VelocityViews * @throws BeansException if no VelocityEngine could be found * @see #getApplicationContext * @see #setVelocityEngine */ protected VelocityEngine autodetectVelocityEngine() throws BeansException { try { VelocityConfig velocityConfig = BeanFactoryUtils.beanOfTypeIncludingAncestors(getApplicationContext(), VelocityConfig.class, true, false); return velocityConfig.getVelocityEngine(); } catch (NoSuchBeanDefinitionException ex) { throw new ApplicationContextException( "Must define a single VelocityConfig bean in this web application context " + "(may be inherited): VelocityConfigurer is the usual implementation. " + "This bean may be given any name.", ex); } }