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

2023-02-13,,,

编写一个类,注册为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();
}
}
}

SpringBoot项目启动后自动打开浏览器的相关教程结束。

《SpringBoot项目启动后自动打开浏览器.doc》

下载本文的Word格式文档,以方便收藏与打印。