便于在 idea 控制台直接打开接口文档地址
1. 效果
2. 代码
/**
* @Description 控制台输出 Swagger 接口文档地址
* @Author Gao Hang Hang
* @Date 2019-12-11 01:09
**/
@Component
@Slf4j
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
private int serverPort;
public int getPort() {
return this.serverPort;
}
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
try {
InetAddress inetAddress = Inet4Address.getLocalHost();
this.serverPort = event.getWebServer().getPort();
log.info("项目启动启动成功!接口文档地址: http://"+inetAddress.getHostAddress()+":"+serverPort+"/swagger-ui.html");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}