弹簧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
答案 0 :(得分:2)
private JavaMailSender javaMailSender;
在您的情况下,您必须调用此属性的setter
private MailSender mailSender;
将在春天自动注入。但
private JavaMailSender javaMailSender;
将为空。
你正在调用javaMailSender.send(mimeMessage);
导致空指针。
使用(JavaMailSender)mailSender.send(mimeMessage);
代替javaMailSender.send(mimeMessage);
答案 1 :(得分:0)