SpringBoot项目启动后自动打开浏览器

编写一个类,注册为Spring的Bean,然后实现CommandLineRunner接口,重写run()方法即可

@Component
public class OpenBrowser implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        System.out.println("开始自动加载指定的页面");
        try {
            Runtime.getRuntime().exec("cmd   /c   start   http://localhost:8080/boot01");//可以指定自己的路径
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
原文地址:https://www.cnblogs.com/juyss/p/13859647.html