From eb95fabcf047acba5b0f650cb0145ea991908ea7 Mon Sep 17 00:00:00 2001 From: jiang4yu Date: Mon, 8 Sep 2025 11:53:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Banner=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- continew-starter-banner/pom.xml | 23 +++++++ .../BannerAutoConfiguration.java | 52 +++++++++++++++ .../autoconfigure/BannerProperties.java | 66 +++++++++++++++++++ .../banner/core/BannerApplicationRunner.java | 46 +++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/banner.txt | 13 ++++ .../src/main/resources/default-banner.yml | 7 ++ continew-starter-bom/pom.xml | 6 ++ pom.xml | 1 + 9 files changed, 215 insertions(+) create mode 100644 continew-starter-banner/pom.xml create mode 100644 continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerAutoConfiguration.java create mode 100644 continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerProperties.java create mode 100644 continew-starter-banner/src/main/java/top/continew/starter/banner/core/BannerApplicationRunner.java create mode 100644 continew-starter-banner/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 continew-starter-banner/src/main/resources/banner.txt create mode 100644 continew-starter-banner/src/main/resources/default-banner.yml diff --git a/continew-starter-banner/pom.xml b/continew-starter-banner/pom.xml new file mode 100644 index 00000000..a6eac057 --- /dev/null +++ b/continew-starter-banner/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + top.continew.starter + continew-starter + ${revision} + + + continew-starter-banner + jar + + ${project.artifactId} + ContiNew Starter Banner 打印模块 + + + + + top.continew.starter + continew-starter-core + + + diff --git a/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerAutoConfiguration.java b/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerAutoConfiguration.java new file mode 100644 index 00000000..c9314fb3 --- /dev/null +++ b/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.starter.banner.autoconfigure; + +import jakarta.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; +import top.continew.starter.banner.core.BannerApplicationRunner; +import top.continew.starter.core.util.GeneralPropertySourceFactory; + +/** + * Banner 自动配置 + * + * @author Charles7c + * @since 1.0.0 + */ +@EnableConfigurationProperties(BannerProperties.class) +@PropertySource(value = "classpath:default-banner.yml", factory = GeneralPropertySourceFactory.class) +public class BannerAutoConfiguration { + + private static final Logger log = LoggerFactory.getLogger(BannerAutoConfiguration.class); + + + @Bean + @ConditionalOnProperty(prefix = "banner", name = "enabled", havingValue = "true", matchIfMissing = true) + public BannerApplicationRunner bannerApplicationRunner(BannerProperties properties) { + return new BannerApplicationRunner(properties); + } + + @PostConstruct + public void postConstruct() { + log.debug("[ContiNew Starter] - Auto Configuration 'Banner' completed initialization."); + } +} diff --git a/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerProperties.java b/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerProperties.java new file mode 100644 index 00000000..c96d149c --- /dev/null +++ b/continew-starter-banner/src/main/java/top/continew/starter/banner/autoconfigure/BannerProperties.java @@ -0,0 +1,66 @@ +package top.continew.starter.banner.autoconfigure; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("banner") +public class BannerProperties { + + private boolean enabled = true; + + private int delaySeconds = 1; + + /** + * 接口文档 + */ + private String apiDocUrl = "https://www.continew.top/api-doc/"; + + /** + * 开发文档 + */ + private String devDocUrl = "https://www.continew.top/starter/guide/quick-start.html"; + + /** + * 开发教程 + */ + private String tutorialUrl = "https://www.continew.top/starter/guide/introduction.html"; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public int getDelaySeconds() { + return delaySeconds; + } + + public void setDelaySeconds(int delaySeconds) { + this.delaySeconds = delaySeconds; + } + + public String getApiDocUrl() { + return apiDocUrl; + } + + public void setApiDocUrl(String apiDocUrl) { + this.apiDocUrl = apiDocUrl; + } + + public String getDevDocUrl() { + return devDocUrl; + } + + public void setDevDocUrl(String devDocUrl) { + this.devDocUrl = devDocUrl; + } + + public String getTutorialUrl() { + return tutorialUrl; + } + + public void setTutorialUrl(String tutorialUrl) { + this.tutorialUrl = tutorialUrl; + } +} diff --git a/continew-starter-banner/src/main/java/top/continew/starter/banner/core/BannerApplicationRunner.java b/continew-starter-banner/src/main/java/top/continew/starter/banner/core/BannerApplicationRunner.java new file mode 100644 index 00000000..df253d49 --- /dev/null +++ b/continew-starter-banner/src/main/java/top/continew/starter/banner/core/BannerApplicationRunner.java @@ -0,0 +1,46 @@ +package top.continew.starter.banner.core; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import top.continew.starter.banner.autoconfigure.BannerProperties; + +import java.util.concurrent.TimeUnit; + +public class BannerApplicationRunner implements ApplicationRunner { + + private static final Logger log = LoggerFactory.getLogger(BannerApplicationRunner.class); + + private static BannerProperties properties; + + public BannerApplicationRunner(BannerProperties properties) { + BannerApplicationRunner.properties = properties; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + try { + // 延迟指定时间,保证输出到结尾 + TimeUnit.SECONDS.sleep(properties.getDelaySeconds()); + log.info(""" + ========================================================== + \\t项目启动成功! + \\t接口文档: {} + \\t开发文档: {} + \\t开发教程: {} + ========================================================== + """, + properties.getApiDocUrl(), + properties.getDevDocUrl(), + properties.getTutorialUrl() + ); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + log.warn("Banner打印被中断", e); + } catch (Exception e) { + log.error("打印Banner时发生错误", e); + } + } +} diff --git a/continew-starter-banner/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-banner/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..6bc24411 --- /dev/null +++ b/continew-starter-banner/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +top.continew.starter.banner.autoconfigure.BannerAutoConfiguration \ No newline at end of file diff --git a/continew-starter-banner/src/main/resources/banner.txt b/continew-starter-banner/src/main/resources/banner.txt new file mode 100644 index 00000000..56549e45 --- /dev/null +++ b/continew-starter-banner/src/main/resources/banner.txt @@ -0,0 +1,13 @@ +${AnsiColor.BRIGHT_YELLOW} + ______ ______ .__ __. .___________. __ .__ __. ___________ __ ____ _______.___________. ___ .______ .___________. _______ .______ + / | / __ \ | \ | | | || | | \ | | | ____\ \ / \ / / / | | / \ | _ \ | || ____|| _ \ +| ,----'| | | | | \| | `---| |----`| | | \| | | |__ \ \/ \/ / ______ | (----`---| |----` / ^ \ | |_) | `---| |----`| |__ | |_) | +| | | | | | | . ` | | | | | | . ` | | __| \ / |______| \ \ | | / /_\ \ | / | | | __| | / +| `----.| `--' | | |\ | | | | | | |\ | | |____ \ /\ / .----) | | | / _____ \ | |\ \----. | | | |____ | |\ \----. + \______| \______/ |__| \__| |__| |__| |__| \__| |_______| \__/ \__/ |_______/ |__| /__/ \__\ | _| `._____| |__| |_______|| _| `._____| + + ${AnsiColor.BLUE}:: ${application.name} :: ${AnsiColor.BRIGHT_RED}v${application.version} (Profile: ${AnsiColor.BRIGHT_YELLOW}${spring.profiles.active}) + ${AnsiColor.BLUE}:: ContiNew Starter :: ${AnsiColor.BRIGHT_RED}v${application.starter} + ${AnsiColor.BLUE}:: Spring Boot :: ${AnsiColor.BRIGHT_RED}v${spring-boot.version} + +${AnsiColor.WHITE} \ No newline at end of file diff --git a/continew-starter-banner/src/main/resources/default-banner.yml b/continew-starter-banner/src/main/resources/default-banner.yml new file mode 100644 index 00000000..e7ec0339 --- /dev/null +++ b/continew-starter-banner/src/main/resources/default-banner.yml @@ -0,0 +1,7 @@ +## Banner 打印配置 +banner: + enable: true + delaySeconds: 1 # 单位秒 + apiDocUrl: "https://www.continew.top/api-doc/" + devDocUrl: "https://www.continew.top/starter/guide/quick-start.html" + tutorialUrl: "https://www.continew.top/starter/guide/introduction.html" diff --git a/continew-starter-bom/pom.xml b/continew-starter-bom/pom.xml index 0a6f532a..04a2d764 100644 --- a/continew-starter-bom/pom.xml +++ b/continew-starter-bom/pom.xml @@ -299,6 +299,12 @@ continew-starter-extension-tenant-core ${revision} + + + top.continew.starter + continew-starter-banner + ${revision} + diff --git a/pom.xml b/pom.xml index 64f861f8..2ab2a963 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ continew-starter-storage continew-starter-license continew-starter-extension + continew-starter-banner -- Gitee