SpringBoot项目启动时自动在浏览器打开

新建配置文件类

/**
 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();
        }
    }
}

然后启动项目即可直接打开默认浏览器

发布了240 篇原创文章 · 获赞 85 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/imxlw00/article/details/102934214