SpringBoot - 經常使用的啓動方式


1.默認啓動方式,使用 SpringApplication 的靜態方法 run 啓動

@SpringBootApplication
public class SpringbootSimpleDemo1Application {git

    public static void main(String[] args) {
        SpringApplication.run(SpringbootSimpleDemo1Application.class, args);
    }
}github


2.new SpringApplication 對象啓動,同上

@SpringBootApplication
public class SpringbootSimpleDemo1Application {web

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(SpringbootSimpleDemo1Application.class);
        application.run(args);
    }
}spring


3.構造器模式啓動,SpringApplicationBuilder

@SpringBootApplication
public class SpringbootSimpleDemo1Application {springboot

    public static void main(String[] args) {
        //第三種 構造者模式
        new SpringApplicationBuilder(SpringbootSimpleDemo1Application.class).build(args).run();
        //new SpringApplicationBuilder().sources(SpringbootSimpleDemo1Application.class).build(args).run();
        //new SpringApplicationBuilder(SpringbootSimpleDemo1Application.class).web(true).run(args);
    }
}app


案例:https://github.com/mengzhang6/springboot-demoui

 

新增spa

public class SpringbootSimpleDemo1Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(BootStart.class).web(true).run(args);
    }

    @SpringBootApplication
    public static class BootStart {

    }
}
相關文章
相關標籤/搜索