重构:按功能初步拆分模块

This commit is contained in:
2022-12-10 21:25:14 +08:00
parent 4ed8ba4709
commit 12b839f297
12 changed files with 264 additions and 92 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.charles7c;
import java.net.InetAddress;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
/**
* 启动程序
*
* @author Charles7c
* @since 2022/12/8 23:15
*/
@Slf4j
@RestController
@SpringBootApplication
public class ContinewAdminApplication {
private static Environment env;
@SneakyThrows
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ContinewAdminApplication.class);
ConfigurableApplicationContext context = application.run(args);
env = context.getEnvironment();
log.info("------------------------------------------------------");
log.info("{} backend service started successfully.", env.getProperty("continew-admin.name"));
log.info("后端 API 地址http://{}:{}", InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"));
log.info("------------------------------------------------------");
}
/**
* 访问首页提示
*
* @return /
*/
@GetMapping("/")
public String index() {
return String.format("%s backend service started successfully.", env.getProperty("continew-admin.name"));
}
}

View File

@@ -0,0 +1,5 @@
--- ### 服务器配置
server:
# HTTP 端口(默认 8080
port: 8000

View File

@@ -0,0 +1,5 @@
--- ### 服务器配置
server:
# HTTP 端口(默认 8080
port: 18000

View File

@@ -0,0 +1,62 @@
--- ### 项目配置
continew-admin:
# 名称
name: ContiNew-Admin
# 应用名称
appName: @project.name@
# 版本
version: @project.version@
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
logging:
level:
top.charles7c: @logging.level@
file:
path: @logging.file.path@
config: classpath:logback-spring.xml
--- ### 服务器配置
server:
servlet:
# 应用访问路径
context-path: /
## Undertow 服务器配置
undertow:
# HTTP POST 请求内容的大小上限(默认 -1 不限制)
max-http-post-size: -1
# 以下的配置会影响 buffer这些 buffer 会用于服务器连接的 IO 操作,有点类似 Netty 的池化内存管理
# 每块 buffer的空间大小越小的空间被利用越充分不要设置太大以免影响其他应用合适即可
buffer-size: 512
# 是否分配的直接内存NIO 直接分配的堆外内存)
direct-buffers: true
threads:
# 设置 IO 线程数,它主要执行非阻塞的任务,它们会负责多个连接(默认每个 CPU 核心一个线程)
io: 8
# 阻塞任务线程池,当执行类似 Servlet 请求阻塞操作Undertow 会从这个线程池中取得线程(它的值设置取决于系统的负载)
worker: 256
--- ### Spring 配置
spring:
application:
name: ${continew-admin.appName}
## 环境配置
profiles:
# 启用的环境
# 配合 Maven Profile 选择不同配置文件进行启动,在 IntelliJ IDEA 右侧 Maven 工具窗口可以快速切换环境
active: @profiles.active@
## JSON 配置
jackson:
# 时区配置
time-zone: GMT+8
# 日期格式化
date-format: yyyy-MM-dd HH:mm:ss
# 序列化配置Bean -> JSON
serialization:
# 是否格式化输出
indent_output: false
# 忽略无法转换的对象
fail_on_empty_beans: false
# 反序列化配置JSON -> Bean
deserialization:
# 忽略 JSON 中不存在的属性
fail_on_unknown_properties: false

View File

@@ -0,0 +1,8 @@
____ _ _ _ _ _ _ _
/ ___| ___ _ __ | |_ (_)| \ | | ___ __ __ / \ __| | _ __ ___ (_) _ __
| | / _ \ | '_ \ | __|| || \| | / _ \\ \ /\ / /_____ / _ \ / _` || '_ ` _ \ | || '_ \
| |___| (_) || | | || |_ | || |\ || __/ \ V V /|_____|/ ___ \| (_| || | | | | || || | | |
\____|\___/ |_| |_| \__||_||_| \_| \___| \_/\_/ /_/ \_\\__,_||_| |_| |_||_||_| |_|
:: ${continew-admin.name} :: v${continew-admin.version}
:: Spring Boot :: v${spring-boot.version}

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别从低到高分为 TRACE < DEBUG < INFO < WARN < ERROR < FATAL如果设置为 WARN则低于 WARN 的信息都不会输出 -->
<!-- scan当此属性设置为 true 时,配置文档如果发生改变,将会被重新加载,默认值为 true -->
<!-- scanPeriod设置监测配置文档是否有修改的时间间隔如果没有给出时间单位默认单位是毫秒。
当 scan 为 true 时,此属性生效。默认的时间间隔为 1 分钟。 -->
<!-- debug当此属性设置为 true 时,将打印出 logback 内部日志信息,实时查看 logback 运行状态。默认值为 false。 -->
<configuration debug="false" scan="true" scanPeriod="30 seconds">
<!-- 应用名 -->
<springProperty name="APP_NAME" source="spring.application.name" scope="context" />
<!-- 保存路径 -->
<property name="LOG_PATH" value="${LOG_PATH:-./logs}" />
<!-- 字符集 -->
<property name="LOG_CHARSET" value="utf-8" />
<!-- 控制台输出格式(带颜色) -->
<!-- 格式化输出:%d 表示日期;%thread 表示线程名;%-5level级别从左显示 5 个字符宽度;%msg日志消息%n 是换行符 -->
<property name="CONSOLE_LOG_PATTERN" value="%red(%d{yyyy-MM-dd HH:mm:ss}) %highlight(%-5level) %green([%thread]) %boldMagenta(%logger{50}) - %msg%n" />
<!-- 文件输出格式 -->
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] %logger{50} - %msg%n"/>
<!-- 输出日志到控制台 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>${LOG_CHARSET}</charset>
</encoder>
</appender>
<!-- 输出日志到文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>${LOG_CHARSET}</charset>
</encoder>
<!-- 循环政策:基于时间和大小创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- 日志文件输出的文件名 -->
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd, aux}/${APP_NAME}.%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern>
<!-- 日志保存 10 天(一小时生成一个,一天 24 个文件) -->
<maxHistory>240</maxHistory>
<!-- 单个日志文件最大的大小 -->
<maxFileSize>20MB</maxFileSize>
</rollingPolicy>
</appender>
<!-- 异步输出日志到文件 -->
<appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志,默认:如果队列的 80% 已满,则会丢弃 TRACT、DEBUG、INFO 级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度该值会影响性能默认256 -->
<queueSize>512</queueSize>
<!-- 添加附加的 appender最多只能添加一个 -->
<appender-ref ref="FILE"/>
</appender>
<!-- 开发环境:只打印到控制台 -->
<springProfile name="dev">
<!-- 如果配置的日志等级,和 application.yml 中的日志等级配置重叠application.yml 配置优先级高 -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<!-- 生产环境:只输出到文件 -->
<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/>
</root>
</springProfile>
</configuration>

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.charles7c;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ContinewAdminApplicationTests {
@Test
void contextLoads() {
}
}