背景:
在不明白SpringBoot原理的情况下,直接新建了SpringBoot工程,然后运行了一下就退出了,还认为SpringBoot出bug了。
其实很简单,我没有引入任何使用场景,比如:web场景,所以没有任何线程池创建出来,所以就退出了。
1)退出现象
"C:\Program Files\Java\jdk-11.0.6\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\IntelliJ IDEA 2020.3.1\lib\idea_rt.jar=54386:D:\IntelliJ IDEA 2020.3.1\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath C:\my_git\other\TestSb\target\classes;C:\Users\jianan\.m2\repository\org\springframework\boot\spring-boot-starter\2.6.4\spring-boot-starter-2.6.4.jar;C:\Users\jianan\.m2\repository\org\springframework\boot\spring-boot\2.6.4\spring-boot-2.6.4.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-context\5.3.16\spring-context-5.3.16.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-aop\5.3.16\spring-aop-5.3.16.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-beans\5.3.16\spring-beans-5.3.16.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-expression\5.3.16\spring-expression-5.3.16.jar;C:\Users\jianan\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.6.4\spring-boot-autoconfigure-2.6.4.jar;C:\Users\jianan\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.6.4\spring-boot-starter-logging-2.6.4.jar;C:\Users\jianan\.m2\repository\ch\qos\logback\logback-classic\1.2.10\logback-classic-1.2.10.jar;C:\Users\jianan\.m2\repository\ch\qos\logback\logback-core\1.2.10\logback-core-1.2.10.jar;C:\Users\jianan\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.1\log4j-to-slf4j-2.17.1.jar;C:\Users\jianan\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;C:\Users\jianan\.m2\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;C:\Users\jianan\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-core\5.3.16\spring-core-5.3.16.jar;C:\Users\jianan\.m2\repository\org\springframework\spring-jcl\5.3.16\spring-jcl-5.3.16.jar;C:\Users\jianan\.m2\repository\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;C:\Users\jianan\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar com.example.demo.DemoApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.4)
2022-03-21 10:19:22.308 INFO 11596 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.6 on jianan with PID 11596 (C:\my_git\other\TestSb\target\classes started by jianan in C:\my_git\other\TestSb)
2022-03-21 10:19:22.308 INFO 11596 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-21 10:19:22.739 INFO 11596 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.779 seconds (JVM running for 1.413)
2)打包 // 使用 clean+package打包,并运行
jianan@jianan MINGW64 /c/my_git/other/TestSb/target
$ java -jar demo-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.4)
2022-03-21 10:25:34.859 INFO 11488 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 11.0.6 on jianan with PID 11488 (C:\my_git\other\TestSb\target\demo-0.0.1-SNAPSHOT.jar started by jianan in C:\my_git\other\TestSb\target)
2022-03-21 10:25:34.859 INFO 11488 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-03-21 10:25:35.298 INFO 11488 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.784 seconds (JVM running for 1.152)
helloWorld
原因:
这是因为我没有引入任何场景,因此,当然会退出了,只有守护线程。
因此我 可以新建一个springboot工程,里面做我的业务即可。只是用一下打包。
同时,我可以非常简单的让SpringBoot工程支持web业务+netty长链接业务。