学习在IDEA中使用SpringBoot(十二)Spring Boot 与任务
2019-08-03 15:43
381 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_41884677/article/details/98326535
一. 异步任务
- 在主类添加
@EnableAsync
开启异步注解功能
- 在service添加
@Async
二. 定时任务
- 在主类
@EnableScheduling
开启基于注解的定时任务
- 在service添加
@Scheduled
三. 邮件任务
-
导入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency>
-
在properties.xml 配置文件中配置属性
spring.mail.username=邮箱名 spring.mail.password=验证码 spring.mail.host=smtp.qq.com spring.mail.properties.mail.smtp.ssl.enable=true
-
test方法
@RunWith(SpringRunner.class) @SpringBootTest public class Springboot04TaskApplicationTests { @Autowired JavaMailSenderImpl mailSender; @Test public void contextLoads() { SimpleMailMessage message = new SimpleMailMessage(); //邮件设置 message.setSubject("通知-今晚开会"); message.setText("今晚7:30开会"); message.setTo("123@163.com"); message.setFrom("456@qq.com"); mailSender.send(message); } @Test public void test02() throws Exception{ //1、创建一个复杂的消息邮件 MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); //邮件设置 helper.setSubject("通知-今晚开会"); helper.setText("<b style='color:red'>今天 7:30 开会</b>",true); helper.setTo("123@163.com"); helper.setFrom("456@qq.com"); //上传文件 helper.addAttachment("1.jpg",new File("C:\\Users\\lfy\\Pictures\\Saved Pictures\\1.jpg")); helper.addAttachment("2.jpg",new File("C:\\Users\\lfy\\Pictures\\Saved Pictures\\2.jpg")); mailSender.send(mimeMessage); } }
相关文章推荐
- SpringBoot入门学习一(如何使用IDEA创建一个SpringBoot应用)
- 学习在IDEA中使用SpringBoot(十五)Spring Boot与热部署
- SpringBoot学习之路:12.Spring Boot使用idea开发如何配置热加载
- 学习在IDEA中使用SpringBoot(十三)Spring Boot 与安全
- Spring Boot 学习15--定时任务的使用
- 使用idea学习SpringBoot整合Mybatis,遇到mapper无法注入的问题
- 01.Spring Cloud学习笔记之使用IDEA+Spring Boot快速构建Rest服务
- 学习在IDEA中使用SpringBoot(十六)Spring Boot与监控管理
- Spring Boot定时任务的使用方法
- Spring学习:使用Spring调度任务
- spring boot 学习(六)spring boot 各版本中使用 log4j2 记录日志
- Spring Boot 定时任务的使用
- 深入学习spring-boot系列(二)--使用spring-data-jpa
- spring boot使用任务调度
- Spring Boot 学习(一)入门及使用
- REDIS学习(3.2)spring boot 使用redis作为缓存
- 深入学习spring-boot系列(二)--使用spring-data-jpa
- 深入学习spring-boot系列(二)--使用spring-data-jpa
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- spring boot 学习(四)Druid连接池的使用配置