File tree Expand file tree Collapse file tree
generator-web/src/main/java/com/softdev/system/generator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import org .springframework .boot .autoconfigure .SpringBootApplication ;
66
77@ SpringBootApplication
8- @ Slf4j
98public class GeneratorWebApplication {
109 public static void main (String [] args ) {
1110 SpringApplication .run (GeneratorWebApplication .class ,args );
12- log .info ("项目启动启动成功!访问地址: http://localhost:1234/generator" );
1311 }
1412}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments