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:定义bean [mailSender,mailMail];工厂层次结构的根
java.lang.NullPointerException
最佳答案
private JavaMailSender javaMailSender;
您必须致电此属性的设置者
private MailSender mailSender;
将在春季自动注入。但
private JavaMailSender javaMailSender;
将为空。
您正在调用javaMailSender.send(mimeMessage);
导致空指针。
使用(JavaMailSender)mailSender.send(mimeMessage);
代替javaMailSender.send(mimeMessage);