Springboot项目启动完成后,自动打开浏览器的配置

原创
2022/04/14 14:18
阅读数 1.2K

1. 增加命令行执行类

@Component
public class StartSuccessful implements CommandLineRunner {
    @Value("${open.browser.url}")
    private String url = "http://localhost:8001/swagger-ui.html";

    [@Override](https://my.oschina.net/u/1162528)
    public void run(String... args) throws Exception {
        System.out.println("开始自动加载指定的页面");
        try {
            //可以指定自己的路径
            Runtime.getRuntime().exec("cmd   /c   start   " + url);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

增加在yml中添加配置

# 启动之后要打开的地址
open:
  browser:
    url: http://localhost:8001/swagger-ui.html

2. 直接启动了添加

try {
	InetAddress addr = InetAddress.getLocalHost();
	System.out.println("Local HostAddress: "+addr.getHostAddress());
	Runtime.getRuntime().exec("cmd   /c   start   http://localhost:8080/");//可以指定自己的路径
} catch (Exception ex) {
	ex.printStackTrace();
}

来源: https://blog.csdn.net/weixin_43852058/article/details/111058061 https://blog.csdn.net/xiaoerbuyu1233/article/details/122962375

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部