Spring发送邮件示例中的错误:Error creating bean with name 'javaMailSender '

Spring中的配置文件applicationContext.xml

<!-- spring对email支持 -->
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="smtp.163.com"/>
		<property name="javaMailProperties">
			<props>
                <prop key="mail.smtp.auth">true</prop>
				<prop key="mail.smtp.timeout">25000</prop>
			</props>
		</property>
		<property name="username" value="spring_test"/>
		<property name="password" value="123456"/>
	</bean>

	<bean id="mailMessage"  class="org.springframework.mail.SimpleMailMessage">
		<property name="from" value="[email protected]"/>
		<property name="subject" value="竞价通知"/>
	</bean>

 出错信息:

Exception   in   thread   "main "   org.springframework.beans.factory.BeanCreationException:   Error   creating   bean   with   name   'javaMailSender '   defined   in   file   [C:\wang\j2ee\shop\MailSender.xml]:   Instantiation   of   bean   failed;   nested   exception   is   org.springframework.beans.BeanInstantiationException:   Could   not   instantiate   bean   class   [org.springframework.mail.javamail.JavaMailSenderImpl]:   Constructor   threw   exception;   nested   exception   is   java.lang.NoClassDefFoundError:   com/sun/mail/util/LineInputStream 
Caused   by:   org.springframework.beans.BeanInstantiationException:   Could   not   instantiate   bean   class   [org.springframework.mail.javamail.JavaMailSenderImpl]:   Constructor   threw   exception;   nested   exception   is   java.lang.NoClassDefFoundError:   com/sun/mail/util/LineInputStream 
Caused   by:   java.lang.NoClassDefFoundError:   com/sun/mail/util/LineInputStream

 

问题来源:

J2EE版本冲突问题

 

解决方法:

将J2EE版本Java EE5 改用j2EE1.4
在lib下添加J2EE中的mail.jar和activation.jar

 

你可能感兴趣的:(java,apache,spring,bean,freemarker)