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开 ...
随机推荐
- ArcGIS 生成要素轮廓线掩膜
先说效果: 生成轮廓之前:
- 转载 Easyui Tree方法扩展 - getLevel(获取节点级别)
Easyui Tree一直就没有提供这个方法,以前没有用到,所 以一直没怎么在意,这次自己用到了,顺便扩展了一个方法,分享给大家. $.extend($.fn.tree.methods, { getL ...
- 兰伯特余弦定理(Lambert)
兰伯特余弦定理(Lambert) 1.漫反射,是投射在粗糙表面上的光向各个方向反射的现象.当一束平行的入射光线射到粗糙的表面时,表面会把光线向着四面八方反射,所以入射线虽然互相平行,由于各点的法线方向 ...
- Euclid`s Game
题目 给定两个整数 a 和 b,Stan和Ollie轮流从较大的数字中减去较小的数的倍数.这里的倍数是指1倍.2倍这样的整数倍,并且相减后的结果不能小于0.Stan先手,在自己的回合将其中一个数变成零 ...
- Codeforces Round #552 (Div. 3)-D-Walking Robot-(贪心)
http://codeforces.com/contest/1154/problem/D 解题: 1.无光的时候优先使用太阳能电池. 2.有光的时候 (1)太阳能电池没满电,让它充,使用普通电池 (2 ...
- 8-网页,网站,微信公众号基础入门(使用Python程序实现微信token验证)
https://www.cnblogs.com/yangfengwu/p/11062034.html 设置一下IP白名单: 填写自己的服务器的IP地址 是不是不可以哈,有多少人都会入这个坑.... ...
- Shared Virtual Memory (SVM) Functions
Description Shared Virtual Memory (SVM) (Glossary): An address space exposed to both the host and th ...
- vue指令用法
vue指令 指令式带有 v- 前缀的特殊特性v-text和v-html都属于指令将数据和dom做关联,当表达式的值改变时,响应式地作用在视图 解决大胡子语法闪烁案例 [v-cloak] { dispa ...
- 使用 Python 和 Flask 设计 RESTful API
近些年来 REST (REpresentational State Transfer) 已经变成了 web services 和 web APIs 的标配. 在本文中我将向你展示如何简单地使用 Pyt ...
- 记一次MyBatisPlus问题(如果表名是数据库关键字怎么办)
问题信息:如果表名是数据库关键字怎么办? 正常来说,如果是我们自己写sql的话,给表名加反引号即可解决问题. 但是由于我们使用MyBatisPlus,相关的sql基本上都是封装并自动生成的.如果是这种 ...