Reputation: 91
Spring-Mail.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="javaMailProperties">
<props>
</property>
</bean>
<bean id="mailMail" class="com.mkyong.common.EmailProcessor">
<property name="mailSender" ref="mailSender" />
</bean>
</beans>
EmailProcessor.java
eBeanFactory@7e78d6c6: defining beans [mailSender,mailMail]; root of factory hierarchy java.lang.NullPointerException
Upvotes: 0
Views: 2816
Reputation: 3042
Go through the below link You can send the mail easily http://javaeasyforu.blogspot.in/2013/10/sending-email-using-spring-mvc.html
Upvotes: 0
Reputation: 10997
private JavaMailSender javaMailSender;
You have to call the setter of this property In your case
private MailSender mailSender;
will be automatically injected by spring. But
private JavaMailSender javaMailSender;
will be null.
And you are calling javaMailSender.send(mimeMessage);
resulting in null pointer.
Use (JavaMailSender)mailSender.send(mimeMessage);
instead of javaMailSender.send(mimeMessage);
Upvotes: 2