• springboot:非web启动


    需要运行一些调度任务,但是又不想放到web容器中运行。 见红色代码:

    import java.util.concurrent.ThreadPoolExecutor;
    
    import org.springframework.boot.WebApplicationType;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.cache.annotation.EnableCaching;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.core.task.AsyncTaskExecutor;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.annotation.EnableScheduling;
    import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
    import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
    
    @SpringBootApplication
    @EnableCaching
    @EnableRedisHttpSession
    @EnableAsync
    @EnableScheduling
    public class JspxScheduleApplication {
    
      public static void main(String[] args) {
        new SpringApplicationBuilder(JspxScheduleApplication.class).web(WebApplicationType.NONE).run(args);
      }
    
      @Bean
      public AsyncTaskExecutor asyncTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix("jspt-schedule-");
        executor.setMaxPoolSize(30);
        executor.setCorePoolSize(10);
        executor.setQueueCapacity(0);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        return executor;
      }
    
    }

    WebApplicationType 有三个值。

    • NONE - 应用程序不应作为Web应用程序运行,也不应启动嵌入式Web服务器。
    • REACTIVE - 应用程序应作为响应式Web应用程序运行,并应启动嵌入式响应式Web服务器。
    • SERVLET - 应用程序应作为基于servlet的Web应用程序运行,并应启动嵌入式servlet Web服务器。
  • 相关阅读:
    如何利用FineBI做财务分析
    mysqlbinlog 读取多个文件
    Chapter 13. Miscellaneous PerlTk Methods PerlTk 方法杂项:
    跨越多台haproxy 跳转
    haproxy redirect prefix
    大数据决策领跑零售业
    大数据决策领跑零售业
    perl 实现微信简版
    perl 调用按钮输出到文本框
    Chapter 11. Frame, MainWindow, and Toplevel Widgets 框架,主窗体,顶级部件
  • 原文地址:https://www.cnblogs.com/huiy/p/11834828.html
Copyright © 2020-2023  润新知