我正在尝试使用 JavaMailSender 在我的 Spring MVC Web 应用程序和 Tomcat 7 中发送注册确认电子邮件,但它始终返回 NullPointerException。谁能帮我找出为什么我得到空指针?以下是我的配置设置:
网页.xml
<!-- jndi mail session -->
<resource-ref>
<description>
Resource reference to a factory for javax.mail.Session
instances that may be used for sending electronic mail
messages, preconfigured to connect to the appropriate
SMTP server.
</description>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
应用程序-servlet.xml
<!-- Mail Sender bean definition -->
<bean id="smtpSession" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/mail/session"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="smtpSession"/>
<!--
<property name="host" value="smtp.gmail.com" />
<property name="port" value="465" />
<property name="username" …Run Code Online (Sandbox Code Playgroud)