写一个类
package com.aaa.pettyloan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
* 项目启动类
*/
@Component
public class MyCommandRunner implements CommandLineRunner {
private static Logger logger = LoggerFactory.getLogger(MyCommandRunner.class);
@Value("${spring.web.loginurl}")
private String loginUrl;
@Value("${spring.web.googleexcute}")
private String googleExcutePath;
@Value("${spring.auto.openurl}")
private boolean isOpen;
@Override
public void run(String... args) throws Exception {
if(isOpen){
String cmd = googleExcutePath +" "+ loginUrl;
Runtime run = Runtime.getRuntime();
try{
run.exec(cmd);
logger.debug("启动浏览器打开项目成功");
}catch (Exception e){
e.printStackTrace();
logger.error(e.getMessage());
}
}
}
}
然后在application.properties配置
#是否自动打开浏览器,
spring.auto.openurl=true
#项目地址
spring.web.loginurl=http://192.168.1.112:8080/pettyloan/login
#浏览器
spring.web.googleexcute=E:\\Mozilla Firefox\\firefox.exe
完成!