SpringBoot设置启动自动打开首页
package com.demo.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; import java.io.IOException; @Configuration public class ToBrowserConfig { @Value("${obj.index.url:http://localhost:7070}") private String url; @EventListener({ApplicationReadyEvent.class}) public void applicationReadyEvent() { Runtime runtime = Runtime.getRuntime(); try { runtime.exec("rundll32 url.dll,FileProtocolHandler " + url); } catch (IOException e) { e.printStackTrace(); } } }
配置文件(只是做个配置,可以不需要这一步)
obj: index: url: http://localhost:7070