0

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>

电子邮件处理器.java

eBeanFactory@7e78d6c6:定义bean [mailSender,mailMail];工厂层次结构的根 java.lang.NullPointerException

4

2 回答 2

2

private JavaMailSender javaMailSender;

你必须调用这个属性的设置器在你的情况下 private MailSender mailSender;,spring会自动注入。但 private JavaMailSender javaMailSender;会为空。

而且您正在调用javaMailSender.send(mimeMessage);导致空指针。

使用(JavaMailSender)mailSender.send(mimeMessage);代替javaMailSender.send(mimeMessage);

于 2013-11-06T04:27:41.943 回答
0

通过以下链接您可以轻松发送邮件 http://javaeasyforu.blogspot.in/2013/10/sending-email-using-spring-mvc.html

于 2013-11-06T07:04:07.550 回答