Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

VelocityEngine Spring Java Config

DZone's Guide to

VelocityEngine Spring Java Config

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

This is a first post in a series of short code snippets that will present the configuration of Spring beans from XML to Java.

XML: 

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
  <property name="velocityProperties">
	 <value>
	  resource.loader=class
	  class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
	 </value>
  </property>
</bean>

Java

@Bean
public VelocityEngine velocityEngine() throws VelocityException, IOException{
	VelocityEngineFactoryBean factory = new VelocityEngineFactoryBean();
	Properties props = new Properties();
	props.put("resource.loader", "class");
	props.put("class.resource.loader.class", 
			  "org.apache.velocity.runtime.resource.loader." + 
			  "ClasspathResourceLoader");
	factory.setVelocityProperties(props);
	
	return factory.createVelocityEngine();
}

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}