SpringBoot异步任务使用方法详解

2020-03-13 16:01:00王振洲

3.添加启动类

package top.ytheng.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

@SpringBootApplication //等于下面3个
//@SpringBootConfiguration
//@EnableAutoConfiguration
//@ComponentScan
//拦截器用到
@ServletComponentScan
//MyBatis用到
@MapperScan("top.ytheng.demo.mapper")
//定时使用(开启定时任务)
@EnableScheduling
//开启异步任务
@EnableAsync
public class DemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}

4.右键项目Run As启动,访问url

http://localhost:8080/api/v1/async/test

结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。