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

时间:2020-10-22 19:30:38   收藏:0   阅读:52

编写一个类,注册为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/shmebluk/p/13859647.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!