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();
        }
    }
}
posted @ 2020-10-22 17:37  juyss  阅读(2156)  评论(0编辑  收藏  举报