springboot-异步、发送邮件(一)
2024-09-05 06:05:43
pom.xml
<!--邮件javax.mail-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
MyController.class
@Controller
public class MyController {
@Autowired
AsyncService asyncService;
@ResponseBody
@GetMapping("/hello")
public String hello(){
asyncService.hello();
return "你好";
}
}
AsyncService.class
@Service
public class AsyncService {
@Async
public void hello(){
try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("数据正在处理。。。。。。");
} }
SpringbootTaskApplication.class
@EnableAsync //开启异步注解功能
@SpringBootApplication
public class SpringbootTaskApplication { public static void main(String[] args) {
SpringApplication.run(SpringbootTaskApplication.class, args);
}
}
application.properties
spring.mail.username=110xxxxx@qq.com
#授权码
spring.mail.password=xxxxxxxxxxxxx
spring.mail.host=smtp.qq.com
#开启加密验证
spring.mail.properties.mail.smtp.ssl.enable=true
SpringbootTaskApplicationTest.class
@SpringBootTest
class SpringbootTaskApplicationTests {
@Autowired
JavaMailSenderImpl mailSender;
@Test
void contextLoads() {
SimpleMailMessage message=new SimpleMailMessage();
message.setSubject("xx你好啊");
message.setText("java这条路行下去");
message.setTo("110xxxxx6@qq.com");
message.setFrom("110xxxxx56@qq.com");
mailSender.send(message);
} }
最新文章
- Xshell访问虚拟机内Linux
- Nam Game
- 通过rsync搭建一个远程备份系统(一)
- 【转贴】全站 HTTPS 来了
- Longest Ordered Subsequence
- APK 代码混淆
- JAVA 统计字符串中中文,英文,数字,空格的个数
- JavaScript绘制表格并将内容以JSON返回后台
- 解决Nginx+Tomcat时ContextPath不同的问题
- Django+Bootstrap+Mysql 搭建个人博客 (六)
- fiddler修改Requests之前的数据和response 之后的数据
- [转] 一张图理解prototype、proto和constructor的三角关系
- 【MySQL】MySQL查询数据库各表的行数
- 基于vue-cli配置手淘的lib-flexible + rem,实现移动端自适应
- exe4j使用说明
- Appium+python自动化3-定位元素
- sys和os模块
- 树莓派3 U盘启动 配置 &; 即 MSD启动 总结
- wmi收集系统信息 发送到服务器打印
- SQL Server Job
热门文章
- redus - 队列
- Docker 版本的更新和安装
- numpy中flatten学习笔记
- c++ for_each
- java+断点续传
- JAVA 基础编程练习题29 【程序 29 求矩阵对角线之和】
- [Python]编译错误:编码错误问题(SyntaxError: (unicode error) )
- Clonezilla克隆还原系统
- 【从零开始搭建K8S】【第一篇】CentOS7.6离线安装Docker(手动安装以及基于yum本地源安装)
- Bulid过程中中遇到的问题UnityEditor.BuildPlayerWindow+BuildMethodException: &#39;&#39; is an incorrect path for a scene file. BuildPlayer expects paths relative to the project folder.