Spring Boot下非web后台长运行应用的实现

栏目: Java · 发布时间: 7年前

内容简介:测试环境:Spring Boot 2.1.1.RELEASE添加之后,应用将不再启动web容器,在

测试环境:Spring Boot 2.1.1.RELEASE

Spring Boot 下非web应用只需在 application.properties 里加上:

spring.main.web-application-type=none

添加之后,应用将不再启动web容器,在 CommandLineRunner 执行完毕后会自动退出,若我们需要长时间运行在后台的应用需在最后加上: new Scanner(System.in).nextLine() ,如:

@SpringBootApplication
public class Netty4ServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(Netty4ServerApplication.class, args);
	}

	@Bean
	CommandLineRunner novaServerRunner(NovaDecoder decoder, NovaEncoder encoder){

		return p -> {
               //...业务逻辑
			new Scanner(System.in).nextLine(); 

		};
	}



}

这时候应用即可在后台运行,在控制台随便输入一行字按回车即可关闭应用。

源码地址: https://github.com/wiselyman/netty4-server.git


以上所述就是小编给大家介绍的《Spring Boot下非web后台长运行应用的实现》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Little Prover

The Little Prover

Daniel P. Friedman、Carl Eastlund / The MIT Press / 2015-7-10 / USD 38.00

[FROM www.amazon.com]: The Little Prover introduces inductive proofs as a way to determine facts about computer programs. It is written in an approachable, engaging style of question-and-answer, wi......一起来看看 《The Little Prover》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具