需要运行一些调度任务,但是又不想放到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服务器。

springboot:非web启动的更多相关文章

  1. springboot非web项目

    使用CommandRunner @SpringBootApplication public class CrmApplication implements ApplicationRunner { @A ...

  2. SpringBoot 非web项目简单架构

    1.截图 2.DemoService package com.github.weiwei02.springcloudtaskdemo; import org.springframework.beans ...

  3. springboot 创建非web项目及数据源简单使用

    项目组马上要使用springboot来重构程序,首先要对几个比较小的非web项目重构,所以新手入门,简单做了个小例子 代码结构如下: dao层 package com.mysping.myboot00 ...

  4. springboot web - 启动(1) 创建SpringApplication

    一. 测试代码 @SpringBootApplication public class SbmvcApplication { public static void main(String[] args ...

  5. springboot 初始化 web 项目 启动报错。。。一直解决不了

    1. 一个简单的SpringBoot项目,启动时报错信息: ERROR 18688 --- [cat-startStop-1] org.apache.catalina.core.ContainerBa ...

  6. Spring Boot移除内嵌Tomcat,使用非web方式启动

    前言:当我们使用Spring Boot编写了一个批处理应用程序,该程序只是用于后台跑批数据,此时不需要内嵌的tomcat,简化启动方式使用非web方式启动项目,步骤如下: 1.在pom.xml文件中去 ...

  7. SpringBoot(12) SpringBoot创建非web应用

    在Spring Boot中,要创建一个非Web应用程序,实现CommandLineRunner并覆盖run()方法 @SpringBootApplication public class Spring ...

  8. SpringBoot整合WEB开发--(八)启动任务系统

    简介: 有一些特殊的任务需要在系统启动时执行,例如配置文件的加载,数据库初始化等操作,如果没有使用SpringBoot,这些问题可以在Listener中解决.SpringBoot提供了两种解决方案:C ...

  9. 从Spring到SpringBoot构建WEB MVC核心配置详解

    目录 理解Spring WEB MVC架构的演变 认识Spring WEB MVC 传统时代的Spring WEB MVC 新时代Spring WEB MVC SpringBoot简化WEB MVC开 ...

随机推荐

  1. Beta冲刺(7/7)——2019.5.28

    所属课程 软件工程1916|W(福州大学) 作业要求 Beta冲刺(7/7)--2019.5.28 团队名称 待就业六人组 1.团队信息 团队名称:待就业六人组 团队描述:同舟共济扬帆起,乘风破浪万里 ...

  2. vue router 中,children 中 path 为空字符串的路由,是默认打开的路由(包括在 el-tabs 中嵌套路由的情况)

    详见该页面的最后一个代码块:https://router.vuejs.org/zh/guide/essentials/nested-routes.html#%E5%B5%8C%E5%A5%97%E8% ...

  3. Mobx | 强大的状态管理工具 | 可以用Mobx来替代掉redux

    来源简书 电梯直达 https://www.jianshu.com/p/505d9d9fe36a Mobx是一个功能强大,上手非常容易的状态管理工具.就连redux的作者也曾经向大家推荐过它,在不少情 ...

  4. D触发器的使用小结

    请查看我的博客园文章,比较详细. https://www.cnblogs.com/CodeWorkerLiMing/p/11964046.html

  5. 浏览器渲染详细过程:重绘、重排和 composite 只是冰山一角

    https://juejin.im/entry/590801780ce46300617c89b8 渲染 这张很经典的图许多人都看过,其中的概念大家应该都很熟悉,也就是这么几个步骤:js修改dom结构或 ...

  6. 几种开放源码的TCP/IP协议栈比较

    http://blog.chinaunix.net/uid-28785506-id-3828286.html 原文地址:几种开放源码的TCP/IP协议栈比较 作者:三点水兽 1.BSD TCP/IP协 ...

  7. SpringBoot整合ActiveMQ发送邮件

    虽然ActiveMQ以被其他MQ所替代,但仍有学习的意义,本文采用邮件发送的例子展示ActiveMQ 1. 生产者1.1 引入maven依赖1.2 application.yml配置1.3 创建配置类 ...

  8. 13--网页,网站,微信公众号基础入门(PHP获取网页的get请求)

    https://www.cnblogs.com/yangfengwu/p/11148976.html 大家在访问网页的时候有没有注意一件事情 现在咱来看这种哈 现在咱做个功能哈,类似于这样 长话短说 ...

  9. A#G/C013

    A#G/C013 A Sorted Arrays 不会/kk B Hamiltonish Path 我是傻逼 如果一条路径不合法,那么把不合法的端点向没出现过的相邻点连过去救星了 C Ants on ...

  10. 第03组 Alpha冲刺(2/4)

    队名:不等式方程组 组长博客 作业博客 团队项目进度 组员一:张逸杰(组长) 过去两天完成的任务: 文字/口头描述: 制定了初步的项目计划,并开始学习一些推荐.搜索类算法 GitHub签入纪录: 暂无 ...