通过运行扩展 CommandLineRunner
的类并添加注释 @EnableAutoConfiguration
,可以从命令行运行Spring Boot应用程序。
该类还需要扩展run方法:
@Override public void run(String... args) throws Exception { // Put your logic here. }
import org.springframework.boot.Banner; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @EnableJpaRepositories @EnableAutoConfiguration public class StaticGenerator2 implements CommandLineRunner { public static void main(String[] args) throws Exception { //disabled banner, don't want to see the spring logo SpringApplication app = new SpringApplication(StaticGenerator2.class); app.setBannerMode(Banner.Mode.OFF); app.setWebEnvironment(false); // Call the run method app.run(args); } @Override public void run(String... args) throws Exception { // Put your logic here. } }