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