springboot项目启动自动跳转到浏览器的操作代码
作者:Bo~Sir
这篇文章主要介绍了springboot项目启动自动跳转到浏览器的操作代码,本文图文实例代码相结合给大家介绍的非常详细,需要的朋友可以参考下
springboot 项目启动自动打开浏览器访问网站设置
在appcation.yml中添加以下代码:
openProject:
isOpen: true
cmd: cmd /c start
web:
openUrl: http://localhost:8080
添加配置RunConfig类:
package com.example.demo.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RunConfig implements CommandLineRunner {
@Value("${openProject.isOpen}")
private boolean isOpen;
@Value("${openProject.web.openUrl}")
private String openUrl;
@Value("${openProject.cmd}")
private String cmd;
@Override
public void run(String... args){
if(isOpen){
String runCmd = cmd + " " + openUrl ;
System.out.println("运行的命令: " + runCmd);
Runtime run = Runtime.getRuntime();
try {
run.exec(runCmd);
System.out.println("启动浏览器打开项目成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("启动项目自动打开浏览器失败");
}
}
}
}
成功自动跳转到登录页面:

到此这篇关于springboot项目启动自动跳转到浏览器的文章就介绍到这了,更多相关springboot项目启动自动跳转到浏览器内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
