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

     

  • 相关阅读:
    UICollectionView
    UIDynamicPPT
    05-UIDynamic
    键盘处理return key-工具条
    源代码管理工具 git
    源代码管理工具
    核心动画09-CATransition转场动画
    核心动画06-时钟(了解)
    Intersect,Minus,union all 和union的区别
    freemarker大于,小于 gt,lt 的用法
  • 原文地址:https://www.cnblogs.com/shiguanzui/p/11973058.html
Copyright © 2011-2022 走看看