新建配置文件类
/**
springboot项目启动之后自动启动默认浏览器
@author xlw
*/
@SpringBootConfiguration
public class AutoStartProjectInDefaultBrowser implements CommandLineRunner {
//注入项目的端口号
@Value("${server.port}")
private String port;
@Override
public void run(String... args) throws Exception {
try {
Runtime.getRuntime().exec("cmd /c start http://localhost:" + port + "/blog");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
然后启动项目即可直接打开默认浏览器