需要运行一些调度任务,但是又不想放到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. Linq入门学习

    千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看完它!!! 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之 ...

  2. flayboard(纯属娱乐,别人做的)

    <iframe id="iframe" src="" frameborder="0" width="100%" h ...

  3. afnetwork moya 都符合通信协议七层模型

    都是在会话层作出优化:安全.存储.会话控制: 在表示层作出数据处理: 在应用层提供请求响应的便捷接口.

  4. python语言(二)列表、字典、集合、文件读写、关系测试

    1.列表 list   代码 s = '王宇建,苏红,邹存才...' # 列表 数字 list l = ['王宇建','苏红','邹存才'] # 一维数组 二维数组 三维数组 # 0 1 2 # 索引 ...

  5. input标签中的accpet

    用法 accept 属性只能与 <input type="file"> 配合使用.它规定能够通过文件上传进行提交的文件类型. 提示:请避免使用该属性.应该在服务器端验证 ...

  6. HDU 6595 Everything Is Generated In Equal Probability (期望dp,线性推导)

    Everything Is Generated In Equal Probability \[ Time Limit: 1000 ms\quad Memory Limit: 131072 kB \] ...

  7. LeetCode 722. Remove Comments

    原题链接在这里:https://leetcode.com/problems/remove-comments/ 题目: Given a C++ program, remove comments from ...

  8. be of + 名词

    语法: “be of +抽象名词(词组)” 表示主语的某种形状或特征,相当于 "be+形容词" 例如: be of value=be valuable  : be of inter ...

  9. Python -- 正则表达式 regular expression

    正则表达式(regular expression) 根据其英文翻译,re模块 作用:用来匹配字符串.  在Python中,正则表达式是特殊的字符序列,检查一个字符串是否与某种模式匹配. 设计思想:用一 ...

  10. pycharm进行个性化设置

    1. 设置主题:Monokai Ctrl+Alt+S: Editor->Color&Fonts->Python 2. 修改[选中内容]颜色 因为用了Monokai主题后,选中内容的 ...