Skip to content

Commit 8b37443

Browse files
authored
Merge pull request #73 from gaohanghang/master
动态获取tomcat启动端口,控制台打印项目访问地址(PR by @gaohanghang )
2 parents b7861ca + eb7760a commit 8b37443

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66

77
@SpringBootApplication
8-
@Slf4j
98
public class GeneratorWebApplication {
109
public static void main(String[] args) {
1110
SpringApplication.run(GeneratorWebApplication.class,args);
12-
log.info("项目启动启动成功!访问地址: http://localhost:1234/generator");
1311
}
1412
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.softdev.system.generator.config;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.boot.web.context.WebServerInitializedEvent;
5+
import org.springframework.context.ApplicationListener;
6+
import org.springframework.stereotype.Component;
7+
8+
/**
9+
* @Description 动态获取tomcat启动端口,控制台打印项目访问地址
10+
* @Author Gao Hang Hang
11+
* @Date 2019-12-27 14:37
12+
**/
13+
@Component
14+
@Slf4j
15+
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
16+
17+
private int serverPort;
18+
19+
public int getPort() {
20+
return this.serverPort;
21+
}
22+
23+
@Override
24+
public void onApplicationEvent(WebServerInitializedEvent event) {
25+
this.serverPort = event.getWebServer().getPort();
26+
//log.info("Get WebServer port {}", serverPort);
27+
log.info("项目启动启动成功!访问地址: http://localhost:{}/generator", serverPort);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)