Merge pull request #73 from gaohanghang/master

动态获取tomcat启动端口,控制台打印项目访问地址(PR by @gaohanghang )
This commit is contained in:
Moshow郑锴
2019-12-29 22:40:20 +08:00
committed by GitHub
2 changed files with 30 additions and 2 deletions

View File

@@ -5,10 +5,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Slf4j
public class GeneratorWebApplication {
public static void main(String[] args) {
SpringApplication.run(GeneratorWebApplication.class,args);
log.info("项目启动启动成功!访问地址: http://localhost:1234/generator");
}
}

View File

@@ -0,0 +1,30 @@
package com.softdev.system.generator.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @Description 动态获取tomcat启动端口控制台打印项目访问地址
* @Author Gao Hang Hang
* @Date 2019-12-27 14:37
**/
@Component
@Slf4j
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
private int serverPort;
public int getPort() {
return this.serverPort;
}
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
this.serverPort = event.getWebServer().getPort();
//log.info("Get WebServer port {}", serverPort);
log.info("项目启动启动成功!访问地址: http://localhost:{}/generator", serverPort);
}
}