SpringBoot在启动后需要手动打开浏览器输入项目首页,非常的麻烦,配置一个自动打开浏览器跳转首页的配置类
@Configuration
public class BrowerAutoConfig {
@EventListener({ApplicationReadyEvent.class})
public void applicationReadyEvent() {
// 这里需要注url:端口号后不加任何地址,跳转项目首页,比如index.html,否则404
String url = "http://localhost:8080";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}