zoukankan      html  css  js  c++  java
  • springboot-异步、发送邮件(一)

     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);
        }
    
    }

     

  • 相关阅读:
    setTimeout,setInterval你不知道的…
    浏览器console的用法
    命题和命题的否定可以同时成立吗?
    Web云笔记--CSS
    dreamweaver代码提示失效
    游戏平台代表--PS4【推荐】
    Mac上好用的视频播放器有哪些?
    新浪博客“网络繁忙请稍后再试”
    人工智能成功识别“色情暴力”信息??…
    JS查错小工具-三生有幸【推荐】
  • 原文地址:https://www.cnblogs.com/shiguanzui/p/11973058.html
Copyright © 2011-2022 走看看