一个比较好的案例需求:在jar包运行成功后自启动浏览器页面
核心注解:
@Configuration
@EventListener({ApplicationReadyEvent.class})
具体实现
代码语言:javascript复制/**
* @author 乐心湖
* @date 2020/7/21 14:04
**/
@Configuration
public class AutoBrower {
@EventListener({ApplicationReadyEvent.class})
public void applicationReadyEvent() {
System.out.println("主控程序部署完毕 ... 启动可视化界面");
String url = "xxx";
startIndex(url);
}
/**
* 启动首页
* @param url
*/
public void startIndex(String url){
String index = url "/index.html";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " index);
} catch (IOException e) {
e.printStackTrace();
}
}
}