編寫一個類,注冊為Spring的Bean,然后實現CommandLineRunner
接口,重寫run()
方法即可
@Component
public class OpenBrowser implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("開始自動加載指定的頁面");
try {
Runtime.getRuntime().exec("cmd /c start http://localhost:8080/boot01");//可以指定自己的路徑
} catch (Exception ex) {
ex.printStackTrace();
}
}
}