在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(); } }