Browse Source

feat(nexo-model): 初始化应用模块配置

- 添加 application.yml 配置文件,集成 Nacos 服务注册与配置中心
- 创建 banner.txt 启动横幅文件
- 新增 IWechatConfigController 控制器类
- 配置 logback-plus.xml 日志输出格式
- 创建 NexoModelApplication 主启动类
- 添加 pom.xml 依赖配置,集成 Spring Cloud Alibaba、MyBatis Plus 等组件
- 在父项目中注册 nexo-model 模块
- 配置 spy.properties 性能分析插件设置
JX.Li 3 weeks ago
parent
commit
525a8a5b4f

+ 99 - 0
nexo-example/nexo-model/pom.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>com.nexo</groupId>
+        <artifactId>nexo-example</artifactId>
+        <version>1.8.2</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>nexo-model</artifactId>
+
+    <description>
+        nexo-model 应用模块
+    </description>
+
+    <dependencies>
+
+        <!-- SpringCloud Alibaba Nacos -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+        </dependency>
+
+        <!-- SpringCloud Alibaba Nacos Config -->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-sentinel</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-log</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-doc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-security</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-mybatis</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-dubbo</artifactId>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.nexo</groupId>
+            <artifactId>nexo-common-seata</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 15 - 0
nexo-example/nexo-model/src/main/java/com/nexo/model/NexoModelApplication.java

@@ -0,0 +1,15 @@
+package com.nexo.model;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
+
+@SpringBootApplication
+public class NexoModelApplication {
+    public static void main(String[] args) {
+        SpringApplication application = new SpringApplication(NexoModelApplication.class);
+        application.setApplicationStartup(new BufferingApplicationStartup(2048));
+        application.run(args);
+        System.out.println("(♥◠‿◠)ノ゙  应用模块启动成功   ლ(´ڡ`ლ)゙  ");
+    }
+}

+ 20 - 0
nexo-example/nexo-model/src/main/java/com/nexo/model/wechat/controller/IWechatConfigController.java

@@ -0,0 +1,20 @@
+package com.nexo.model.wechat.controller;
+
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/config")
+public class IWechatConfigController {
+
+    @GetMapping("/notice")
+    public String notice() {
+        return "hello world";
+    }
+
+}

+ 32 - 0
nexo-example/nexo-model/src/main/resources/application.yml

@@ -0,0 +1,32 @@
+# Tomcat
+server:
+  port: 9402
+
+# Spring
+spring:
+  application:
+    # 应用名称
+    name: nexo-model
+  profiles:
+    # 环境配置
+    active: @profiles.active@
+
+--- # nacos 配置
+spring:
+  cloud:
+    nacos:
+      # nacos 服务地址
+      server-addr: @nacos.server@
+      discovery:
+        # 注册组
+        group: @nacos.discovery.group@
+        namespace: ${spring.profiles.active}
+      config:
+        # 配置组
+        group: @nacos.config.group@
+        namespace: ${spring.profiles.active}
+  config:
+    import:
+      - optional:nacos:application-common.yml
+      - optional:nacos:nexo-resource.yml
+      - optional:nacos:datasource.yml

+ 10 - 0
nexo-example/nexo-model/src/main/resources/banner.txt

@@ -0,0 +1,10 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+                        _           _
+                       (_)         | |
+ _ __ _   _  ___  _   _ _ ______ __| | ___ _ __ ___   ___
+| '__| | | |/ _ \| | | | |______/ _` |/ _ \ '_ ` _ \ / _ \
+| |  | |_| | (_) | |_| | |     | (_| |  __/ | | | | | (_) |
+|_|   \__,_|\___/ \__, |_|      \__,_|\___|_| |_| |_|\___/
+                   __/ |
+                  |___/

+ 23 - 0
nexo-example/nexo-model/src/main/resources/logback-plus.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true" scanPeriod="60 seconds" debug="false">
+    <!-- 日志存放路径 -->
+	<property name="log.path" value="logs/${project.artifactId}" />
+   <!-- 日志输出格式 -->
+    <property name="console.log.pattern"
+              value="%red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}%n) - %msg%n"/>
+
+    <!-- 控制台输出 -->
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>${console.log.pattern}</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+    </appender>
+
+    <include resource="logback-common.xml" />
+
+	<!--系统操作日志-->
+    <root level="info">
+        <appender-ref ref="console" />
+    </root>
+</configuration>

+ 28 - 0
nexo-example/nexo-model/src/main/resources/spy.properties

@@ -0,0 +1,28 @@
+# p6spy 性能分析插件配置文件
+modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
+# 自定义日志打印
+logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
+#日志输出到控制台
+appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
+# 使用日志系统记录 sql
+#appender=com.p6spy.engine.spy.appender.Slf4JLogger
+# 设置 p6spy driver 代理
+#deregisterdrivers=true
+# 取消JDBC URL前缀
+useprefix=true
+# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
+excludecategories=info,debug,result,commit,resultset
+# 日期格式
+dateformat=yyyy-MM-dd HH:mm:ss
+# SQL语句打印时间格式
+databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
+# 实际驱动可多个
+#driverlist=org.h2.Driver
+# 是否开启慢SQL记录
+outagedetection=true
+# 慢SQL记录标准 2 秒
+outagedetectioninterval=2
+# 是否过滤 Log
+filter=true
+# 过滤 Log 时所排除的 sql 关键字,以逗号分隔
+exclude=SELECT 1

+ 1 - 0
nexo-example/pom.xml

@@ -11,6 +11,7 @@
     <modules>
         <module>nexo-demo</module>
         <module>nexo-stream-mq</module>
+        <module>nexo-model</module>
     </modules>
 
     <artifactId>nexo-example</artifactId>