springboot使用方便,如果想使用springboot开发非web应用,只需要入口程序实现CommandLineRunner
接口,Override run方法,即可。run方法为应用入口。
package com.bus.socketserver; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication public class SocketServerApplication implements CommandLineRunner { @SuppressWarnings("all") @Override public void run(String... args) throws Exception { System.in.read(); } public static void main(String[] args) { SpringApplication.run(SocketServerApplication.class, args); } }