日期:2014-05-17 浏览次数:20793 次
2013-04-13 11:36:42,507 org.springframework.web.context.ContextLoader:215
{ERROR}:Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService': Injection of resource methods failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.mail.internet.MimeMessage] is defined: Unsatisfied dependency of type [class javax.mail.internet.MimeMessage]: expected at least 1 matching bean
@Component("mailService")
@Transactional
public class MailServiceImpl implements IMailService{
private JavaMailSender mailSender;
private MimeMessage mimeMessage;
//private static Logger logger = Logger.getLogger(MailServiceImpl.class);
@Override
public void sendMail(MailFormBeans mail) {
try {
MimeMessageHelper mailMessage = new MimeMessageHelper(this.mimeMessage, true, "UTF-8");
// 设置邮件消息的发送者
mailMessage.setFrom(mail.getMailSender());
// 设置邮件消息的主题
mailMessage.setSubject(mail.getMailSubject());
// 设置邮件消息发送的时间
mailMessage.setSentDate(new Date());
// 设置邮件正文,true表示以html的格式发送
mailMessage.setText(mail.getMailContent(), true);
// 得到要发送的地址数组
String[] toAddresses = mail.getMailReciver().split(";");
for (int i = 0; i < toAddresses.length; i++) {
mailMessage.setTo(toAddresses[i]);
// 发送邮件
this.mailSender.send(this.mimeMessage);
System.out.println("Mail ServiceImpl执行成功");
}
} catch (Exception e) {
//logger.error(e);
e.printStackTrace();
}
}
public JavaMailSender getMailSender() {
return mailSender;
}
@Resource
public void setMailSender(JavaMailSender mailSender) {
this.mailSender = mailSender;
}
public MimeMessage getMimeMessage() {
return mimeMessage;
}
@Resource
public void setMimeMessage(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
}
}