实现的方式本质上是通过命令调用浏览器访问某一路径,打成jar包后依旧有效
在项目中加入如下配置类:
package com.laob.laob_specialmon;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import java.io.IOException;
/**
* @author zhangh
* @version V1.0.0
* @projectName laob_special
* @title IndexConfig
* @package com.laob.laob_specialmon
* @date 2019/9/10 19:07
* @explain 服务启动时自动打开项目
*/
@Configuration
public class IndexConfig {
@EventListener({ApplicationReadyEvent.class})
void applicationReadyEvent() {
System.out.println("Portboy准备就绪 ... 启动浏览器");
// 启动后访问地址
String url = "http://localhost:8090";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}
实现的方式本质上是通过命令调用浏览器访问某一路径,打成jar包后依旧有效
在项目中加入如下配置类:
package com.laob.laob_specialmon;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import java.io.IOException;
/**
* @author zhangh
* @version V1.0.0
* @projectName laob_special
* @title IndexConfig
* @package com.laob.laob_specialmon
* @date 2019/9/10 19:07
* @explain 服务启动时自动打开项目
*/
@Configuration
public class IndexConfig {
@EventListener({ApplicationReadyEvent.class})
void applicationReadyEvent() {
System.out.println("Portboy准备就绪 ... 启动浏览器");
// 启动后访问地址
String url = "http://localhost:8090";
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}
}
}