SpringBoot程序启动后自动打开浏览器

package com.nihaorz.docker.console;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;
import java.io.IOException;

@SpringBootApplication
public class DockerConsoleApplication {

    public static void main(String[] args) {
        int port = 8080;
        String portPrefix = "--server.port=";
        for (String arg : args) {
            if (arg.startsWith(portPrefix)) {
                port = Integer.parseInt(arg.substring(portPrefix.length()));
            }
        }
        SpringApplication.run(DockerConsoleApplication.class, args);
        try {
            Runtime.getRuntime().exec("cmd /c start http://localhost:" + port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

  

posted @ 2020-08-26 13:54  Nihaorz  阅读(2873)  评论(0编辑  收藏  举报