栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot项目自启动浏览器网页

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot项目自启动浏览器网页

新建类,自己指定打开页面
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class BootStartConfig implements CommandLineRunner {

    @Override
    public void run(String... args) {
        try {
            //指定自己的网址路径,使用cmd命令行打开
            Runtime.getRuntime().exec("cmd   /c   start   http://localhost:8080/house");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
新建类,自动获取端口文件配置打开
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class BootStartConfig implements CommandLineRunner {

    //获取配置文件端口和路径名
    @Value("${server.port}")
    private String port;
    @Value("${server.servlet.context-path}")
    private String path;

    @Override
    public void run(String... args) {
        try {
        	//指定自己的网址路径,使用cmd命令行打开
            Runtime.getRuntime().exec("cmd   /c   start   http://localhost:"+port+path);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/434954.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号