lhw901013
2019-04-03 16:09
sendMessageTest(com.neo.helloWord.service.ServiceTest) Time elapsed: 0.026 sec <<< ERROR!
java.lang.NullPointerException: null
at com.neo.helloWord.hello.MailService.sendSimpleMail(MailService.java:34)
at com.neo.helloWord.service.ServiceTest.sendMessageTest(ServiceTest.java:26)
2019-04-03 16:06:14.461 INFO 5236 --- [ Thread-2] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@26275bef: startup date [Wed Apr 03 16:06:10 CST 2019]; root of context hierarchy
Results :
Tests in error:
ServiceTest.sendMessageTest:26 ? NullPointer
请问这个问题解决了吗
java.lang.NullPointerException
报的是这个错误,下面是代码内容
try{ Hello h = new Hello(); h.SimpleEmail("shizengs@aliyun.com", "This is Subject", "This is Content"); }catch (Exception e){ System.out.println(e); }
@RestController public class Hello { @Value("${spring.mail.username}") private String from; @Autowired private JavaMailSender mailSender; @RequestMapping(value="/sendEmail", method = RequestMethod.GET) public void SimpleEmail(String to, String subject, String content){ SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setTo(to); simpleMailMessage.setSubject(subject); simpleMailMessage.setText(content); simpleMailMessage.setFrom(from); mailSender.send(simpleMailMessage); } }
我也遇到了,请问你是怎么解决的
spring boot实现邮箱验证码注册
https://blog.csdn.net/IndexMan/article/details/89409512
Spring Boot 发送邮件
15289 学习 · 56 问题
相似问题