在Application的主界面添加
@SpringBootApplication
public class BackendApp extends WebMvcConfigurationSupport {
public static void main(String[] args) { //System.out.println("端口启动"); SpringApplication.run(BackendApp.class, args); } @Value("${server.port}") private String appport; //站点端口号 /*当端口启动后,直接跳转界面*/ @EventListener({ApplicationReadyEvent.class}) void applicationReadyEvent() { System.out.println("应用已经准备就绪 ... 启动浏览器"); String url = "http://localhost:" + appport; Runtime runtime = Runtime.getRuntime(); try { runtime.exec("rundll32 url.dll,FileProtocolHandler " + url); } catch (IOException e) { e.printStackTrace(); } }