From 7b98b08b57b2e071a795a96081814ed467ca51e8 Mon Sep 17 00:00:00 2001 From: zichun Date: Mon, 1 Jun 2026 13:18:09 +0800 Subject: [PATCH] chore(usr): 初始化 backend Maven 骨架与启动类 --- backend/checkstyle.xml | 32 ++++++++++++++++++++++++++++++++ backend/pom.xml | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/src/main/java/com/xly/erp/ErpApplication.java | 19 +++++++++++++++++++ backend/src/main/resources/application-test.yml | 17 +++++++++++++++++ backend/src/main/resources/application.yml | 37 +++++++++++++++++++++++++++++++++++++ backend/src/test/java/com/xly/erp/ErpApplicationTests.java | 21 +++++++++++++++++++++ 6 files changed, 257 insertions(+), 0 deletions(-) create mode 100644 backend/checkstyle.xml create mode 100644 backend/pom.xml create mode 100644 backend/src/main/java/com/xly/erp/ErpApplication.java create mode 100644 backend/src/main/resources/application-test.yml create mode 100644 backend/src/main/resources/application.yml create mode 100644 backend/src/test/java/com/xly/erp/ErpApplicationTests.java diff --git a/backend/checkstyle.xml b/backend/checkstyle.xml new file mode 100644 index 0000000..37af12a --- /dev/null +++ b/backend/checkstyle.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/pom.xml b/backend/pom.xml new file mode 100644 index 0000000..54b73cc --- /dev/null +++ b/backend/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + + + com.xly + erp-backend + 1.0.0 + jar + xly-erp-backend + 小羚羊 ERP 后端服务 + + + 17 + 17 + UTF-8 + 3.5.7 + 10.10.0 + 0.12.5 + 5.8.27 + 3.3.1 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-security + + + + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatis-plus.version} + + + + + com.mysql + mysql-connector-j + runtime + + + + + org.flywaydb + flyway-core + ${flyway.version} + + + org.flywaydb + flyway-mysql + ${flyway.version} + + + + + io.jsonwebtoken + jjwt-api + ${jjwt.version} + + + io.jsonwebtoken + jjwt-impl + ${jjwt.version} + runtime + + + io.jsonwebtoken + jjwt-jackson + ${jjwt.version} + runtime + + + + + cn.hutool + hutool-core + ${hutool.version} + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + erp-backend + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle.plugin.version} + + checkstyle.xml + true + true + false + + + + + diff --git a/backend/src/main/java/com/xly/erp/ErpApplication.java b/backend/src/main/java/com/xly/erp/ErpApplication.java new file mode 100644 index 0000000..fb9ddf7 --- /dev/null +++ b/backend/src/main/java/com/xly/erp/ErpApplication.java @@ -0,0 +1,19 @@ +package com.xly.erp; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * 小羚羊 ERP 后端启动类。 + * + *

REQ-USR-001: 项目首个后端 REQ,初始化 Maven 骨架与公共基础设施。

+ */ +@SpringBootApplication +@MapperScan("com.xly.erp.**.mapper") +public class ErpApplication { + + public static void main(String[] args) { + SpringApplication.run(ErpApplication.class, args); + } +} diff --git a/backend/src/main/resources/application-test.yml b/backend/src/main/resources/application-test.yml new file mode 100644 index 0000000..ef9f7d1 --- /dev/null +++ b/backend/src/main/resources/application-test.yml @@ -0,0 +1,17 @@ +# application-test.yml — 测试 profile。 +# 连同一测试库(xlyweberp_vibe_erp_test,由 setup-test-db.mjs DROP+CREATE 后由 Flyway apply V1)。 +# 测试期间 Flyway 自动 apply sql/migrations/ 下的 V1+;DB 凭据沿用主配置默认(来自 config-vars.yaml)。 +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${DB_HOST:118.178.19.35}:${DB_PORT:3318}/${DB_SCHEMA:xlyweberp_vibe_erp_test}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true + username: ${DB_USER:xlyprint} + password: ${DB_PASSWORD:xlyXLYprint2016} + flyway: + enabled: true + locations: filesystem:../sql/migrations + baseline-on-migrate: true + +jwt: + secret: ${JWT_SECRET:a3b7e8f1c4d6029e5b8f37a1c9d2e4068b5f1d3a7c0e9b2f48d6a1c5e7f9b3d2} + expire-millis: 43200000 diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml new file mode 100644 index 0000000..24fa4d8 --- /dev/null +++ b/backend/src/main/resources/application.yml @@ -0,0 +1,37 @@ +# application.yml — 小羚羊 ERP 后端主配置。 +# 端口 / 数据源 / MyBatis-Plus / Flyway / JWT。 +# 敏感值(DB 凭据 / JWT 密钥)通过环境变量注入,单一来源为仓库根 config-vars.yaml, +# 由工具脚本 / 部署环境导出为下列 env,禁止硬编码进源码。 +server: + port: ${BACKEND_HTTP_PORT:5172} + +spring: + application: + name: xly-erp-backend + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://${DB_HOST:118.178.19.35}:${DB_PORT:3318}/${DB_SCHEMA:xlyweberp_vibe_erp_test}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true + username: ${DB_USER:xlyprint} + password: ${DB_PASSWORD:xlyXLYprint2016} + flyway: + enabled: true + locations: filesystem:../sql/migrations + baseline-on-migrate: true + table: flyway_schema_history + +mybatis-plus: + configuration: + map-underscore-to-camel-case: false + global-config: + db-config: + id-type: auto + +# JWT 配置:密钥单一来源 config-vars.yaml secrets.jwt_secret,通过 env 注入。 +jwt: + secret: ${JWT_SECRET:a3b7e8f1c4d6029e5b8f37a1c9d2e4068b5f1d3a7c0e9b2f48d6a1c5e7f9b3d2} + # 过期时间(毫秒),默认 12 小时 + expire-millis: ${JWT_EXPIRE_MILLIS:43200000} + +logging: + level: + com.xly.erp: INFO diff --git a/backend/src/test/java/com/xly/erp/ErpApplicationTests.java b/backend/src/test/java/com/xly/erp/ErpApplicationTests.java new file mode 100644 index 0000000..71776cf --- /dev/null +++ b/backend/src/test/java/com/xly/erp/ErpApplicationTests.java @@ -0,0 +1,21 @@ +package com.xly.erp; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +/** + * 骨架健康自检:证明 pom 依赖 / 启动类 / application.yml 自洽, + * Flyway 能对测试库 apply V1,MyBatis-Plus 装配成功。 + * + *

REQ-USR-001 T1。

+ */ +@SpringBootTest +@ActiveProfiles("test") +class ErpApplicationTests { + + @Test + void contextLoads() { + // Spring 上下文成功加载即通过。 + } +} -- libgit2 0.22.2