Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use velocity 1.7 with Spring
    primarykey
    data
    text
    <p>I am using velocity 1.7 withe spring 3.1 framework for sending email. velocity is used for email templates.</p> <p>Below is the configuration </p> <pre><code>&lt;bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"&gt; &lt;property name="velocityProperties"&gt; &lt;props&gt; &lt;prop key="resource.loader"&gt;class&lt;/prop&gt; &lt;prop key="class.resource.loader.class"&gt; org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader &lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>and below is my code </p> <pre><code> @Component public class EmailUtils { @Autowired private static VelocityEngine velocityEngine; public static void sendMail(String subject, Map data, String template, String toName, String toAddress) { HtmlEmail email = new HtmlEmail(); try { email.setHostName(hostName); email.setSmtpPort(smtpPort); email.setSubject(subject); System.out.println(template +" template"); System.out.println(data +" data "); System.out.println(velocityEngine +" velocityEngine "); String message = VelocityEngineUtils.mergeTemplateIntoString( velocityEngine, template, data); System.out.println(message +" message message "); email.setMsg(message); email.addTo(toAddress, toName); email.setFrom(fromAddress, fromName); email.send(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>When I run the application I get following error.</p> <pre><code>java.lang.NullPointerException at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58) </code></pre> <p>as the velocity engine is null.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"&gt; &lt;bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"&gt; &lt;property name="velocityProperties"&gt; &lt;props&gt; &lt;prop key="resource.loader"&gt;class&lt;/prop&gt; &lt;prop key="class.resource.loader.class"&gt; org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader &lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p></p> <p>Please help me. Is there any other configuration that I need to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload