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服务器。
springboot:非web启动的更多相关文章
- springboot非web项目
使用CommandRunner @SpringBootApplication public class CrmApplication implements ApplicationRunner { @A ...
- SpringBoot 非web项目简单架构
1.截图 2.DemoService package com.github.weiwei02.springcloudtaskdemo; import org.springframework.beans ...
- springboot 创建非web项目及数据源简单使用
项目组马上要使用springboot来重构程序,首先要对几个比较小的非web项目重构,所以新手入门,简单做了个小例子 代码结构如下: dao层 package com.mysping.myboot00 ...
- springboot web - 启动(1) 创建SpringApplication
一. 测试代码 @SpringBootApplication public class SbmvcApplication { public static void main(String[] args ...
- springboot 初始化 web 项目 启动报错。。。一直解决不了
1. 一个简单的SpringBoot项目,启动时报错信息: ERROR 18688 --- [cat-startStop-1] org.apache.catalina.core.ContainerBa ...
- Spring Boot移除内嵌Tomcat,使用非web方式启动
前言:当我们使用Spring Boot编写了一个批处理应用程序,该程序只是用于后台跑批数据,此时不需要内嵌的tomcat,简化启动方式使用非web方式启动项目,步骤如下: 1.在pom.xml文件中去 ...
- SpringBoot(12) SpringBoot创建非web应用
在Spring Boot中,要创建一个非Web应用程序,实现CommandLineRunner并覆盖run()方法 @SpringBootApplication public class Spring ...
- SpringBoot整合WEB开发--(八)启动任务系统
简介: 有一些特殊的任务需要在系统启动时执行,例如配置文件的加载,数据库初始化等操作,如果没有使用SpringBoot,这些问题可以在Listener中解决.SpringBoot提供了两种解决方案:C ...
- 从Spring到SpringBoot构建WEB MVC核心配置详解
目录 理解Spring WEB MVC架构的演变 认识Spring WEB MVC 传统时代的Spring WEB MVC 新时代Spring WEB MVC SpringBoot简化WEB MVC开 ...
随机推荐
- M × N Puzzle
http://poj.org/problem?id=2893 来自逆序对的强大力量 #include<iostream> #include<stdio.h> #include& ...
- Oracle的去重函数 distinct
原贴地址:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html#m0 SQL中distinct的用法 1.作用于单列 2.作 ...
- mySql 常用命令 | 珠峰培训例子
show databases; use mhxy; select database(); show tables; desc account_list_175; ),(); select from_u ...
- 关于Classloader(学习笔记)
1)类加载的过程是怎么样的?①加载:根据具体需求,选择合适的加载器(Bootstrap ClassLoader不可直接获取.Extension ClassLoader.系统.自定义)来控制字节流的获取 ...
- Linux安全加固(二)禁止普通用户su到root/设置SSH终端接入白名单/修改history条数
一.禁止普通用户su到root管理员.设置可以su到root的白名单 1.首先看一下正常情况 2.可以看到普通用户使用su root命令,输入密码即可登录到root用户 3.下面开始配置禁止所有普通用 ...
- MySQL 练习题目 二刷 - 2019-11-4 5:55 am
建表的过程 create table student( sid int not null primary key, sname ) not null, sborn date, ssex ) not n ...
- Entity Framework Core Query Types
This feature was added in EF Core 2.1 Query types are non-entity types (classes) that form part of t ...
- Linux OOM一二三
Linux开发一般会遇到“/proc/sys/vm/overcommit_memory”,即文件/etc/sysctl.conf中的vm.overcommit_memory,Overcommit的意思 ...
- 洛谷 P1825 【[USACO11OPEN]玉米田迷宫Corn Maze】
P1825 传送门 简单的题意 就是一个有传送门的迷宫问题(我一开始以为是只有1个传送门,然后我就凉了). 大体思路 先把传送门先存起来,然后跑一下\(BFS\). 然后,就做完了. 代码鸭 #inc ...
- 假设检验总结以及如何用python进行假设检验(scipy)
几种常见的假设检验总结如下: 假设检验名称 Z检验 t检验 χ2检验 F检验 原假设 H0: μ≥μ0 H0: μ≤μ0 H0: μ=μ0 (比较样本和总体均值) ...