新建类,自己指定打开页面
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class BootStartConfig implements CommandLineRunner {
@Override
public void run(String... args) {
try {
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 {
Runtime.getRuntime().exec("cmd /c start http://localhost:"+port+path);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}