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后台长运行应用的实现》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Realm of Racket

Realm of Racket

Matthias Felleisen、Conrad Barski M.D.、David Van Horn、Eight Students Northeastern University of / No Starch Press / 2013-6-25 / USD 39.95

Racket is the noble descendant of Lisp, a programming language renowned for its elegance and power. But while Racket retains the functional goodness of Lisp that makes programming purists drool, it wa......一起来看看 《Realm of Racket》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具