From eb7760ac18139088bdbdfe110d25e242f9257c67 Mon Sep 17 00:00:00 2001 From: gaohanghang <1341947277@qq.com> Date: Fri, 27 Dec 2019 14:43:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=8E=B7=E5=8F=96tomcat?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=AB=AF=E5=8F=A3=EF=BC=8C=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E6=89=93=E5=8D=B0=E9=A1=B9=E7=9B=AE=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/GeneratorWebApplication.java | 2 -- .../system/generator/config/ServerConfig.java | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java diff --git a/generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java b/generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java index 26b799e..d009d5e 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java +++ b/generator-web/src/main/java/com/softdev/system/generator/GeneratorWebApplication.java @@ -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"); } } diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java b/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java new file mode 100644 index 0000000..ada0a1b --- /dev/null +++ b/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java @@ -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 { + + 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); + } + +}