用Srping Boot 写一个 Hello world
用Srping Boot 写一个 Hello world
一般我们在学习一门新的语言时,这里我没有换语言,还是使用java,只是不同于普通的使用main方法的java程序,而是使用SpringBoot来写一个最简单的“Hello world”程序。
TODO 相关使用场景
通过实现ApplicationRunner接口来实现程序启动时执行
ApplicationRunner
package com.github.niushuai1991.jarapp;import org.springframework.boot.CommandLineRunner;import org.springframework.stereotype.Component;@Componentpublic class MyCommandLineRunner implements CommandLineRunner {@Overridepublic void run(String... args) {System.out.println("Hello world! CommandLineRunner");}}
通过实现CommandLineRunner接口来实现程序启动时执行
package com.github.niushuai1991.jarapp;import org.springframework.boot.ApplicationArguments;import org.springframework.boot.ApplicationRunner;import org.springframework.stereotype.Component;@Componentpublic class MyApplicationRunner implements ApplicationRunner {@Overridepublic void run(ApplicationArguments args) {System.out.println("Hello world! ApplicationRunner");}}
当程序启动后,我们在控制台里就能看到以输出内容:
Hello world! ApplicationRunnerHello world! CommandLineRunner

浙公网安备 33010602011771号