Commit 76218f38b9d2439bd2f147ea50963124ea1d202b
1 parent
6faf3c34
feat(usr): bootstrap spring boot 后端骨架 REQ-USR-001
Showing
6 changed files
with
231 additions
and
0 deletions
backend/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | + <modelVersion>4.0.0</modelVersion> | |
| 6 | + | |
| 7 | + <parent> | |
| 8 | + <groupId>org.springframework.boot</groupId> | |
| 9 | + <artifactId>spring-boot-starter-parent</artifactId> | |
| 10 | + <version>3.3.4</version> | |
| 11 | + <relativePath/> | |
| 12 | + </parent> | |
| 13 | + | |
| 14 | + <groupId>com.xly.erp</groupId> | |
| 15 | + <artifactId>xly-erp-backend</artifactId> | |
| 16 | + <version>0.0.1-SNAPSHOT</version> | |
| 17 | + <packaging>jar</packaging> | |
| 18 | + <name>xly-erp-backend</name> | |
| 19 | + <description>小羚羊 ERP 后端</description> | |
| 20 | + | |
| 21 | + <properties> | |
| 22 | + <java.version>17</java.version> | |
| 23 | + <maven.compiler.source>17</maven.compiler.source> | |
| 24 | + <maven.compiler.target>17</maven.compiler.target> | |
| 25 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| 26 | + <mybatis-plus.version>3.5.7</mybatis-plus.version> | |
| 27 | + <jjwt.version>0.12.5</jjwt.version> | |
| 28 | + </properties> | |
| 29 | + | |
| 30 | + <dependencies> | |
| 31 | + <dependency> | |
| 32 | + <groupId>org.springframework.boot</groupId> | |
| 33 | + <artifactId>spring-boot-starter-web</artifactId> | |
| 34 | + </dependency> | |
| 35 | + <dependency> | |
| 36 | + <groupId>org.springframework.boot</groupId> | |
| 37 | + <artifactId>spring-boot-starter-validation</artifactId> | |
| 38 | + </dependency> | |
| 39 | + <dependency> | |
| 40 | + <groupId>org.springframework.security</groupId> | |
| 41 | + <artifactId>spring-security-crypto</artifactId> | |
| 42 | + </dependency> | |
| 43 | + | |
| 44 | + <dependency> | |
| 45 | + <groupId>com.baomidou</groupId> | |
| 46 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> | |
| 47 | + <version>${mybatis-plus.version}</version> | |
| 48 | + </dependency> | |
| 49 | + | |
| 50 | + <dependency> | |
| 51 | + <groupId>com.mysql</groupId> | |
| 52 | + <artifactId>mysql-connector-j</artifactId> | |
| 53 | + <scope>runtime</scope> | |
| 54 | + </dependency> | |
| 55 | + | |
| 56 | + <dependency> | |
| 57 | + <groupId>org.flywaydb</groupId> | |
| 58 | + <artifactId>flyway-core</artifactId> | |
| 59 | + </dependency> | |
| 60 | + <dependency> | |
| 61 | + <groupId>org.flywaydb</groupId> | |
| 62 | + <artifactId>flyway-mysql</artifactId> | |
| 63 | + </dependency> | |
| 64 | + | |
| 65 | + <dependency> | |
| 66 | + <groupId>io.jsonwebtoken</groupId> | |
| 67 | + <artifactId>jjwt-api</artifactId> | |
| 68 | + <version>${jjwt.version}</version> | |
| 69 | + </dependency> | |
| 70 | + <dependency> | |
| 71 | + <groupId>io.jsonwebtoken</groupId> | |
| 72 | + <artifactId>jjwt-impl</artifactId> | |
| 73 | + <version>${jjwt.version}</version> | |
| 74 | + <scope>runtime</scope> | |
| 75 | + </dependency> | |
| 76 | + <dependency> | |
| 77 | + <groupId>io.jsonwebtoken</groupId> | |
| 78 | + <artifactId>jjwt-jackson</artifactId> | |
| 79 | + <version>${jjwt.version}</version> | |
| 80 | + <scope>runtime</scope> | |
| 81 | + </dependency> | |
| 82 | + | |
| 83 | + <dependency> | |
| 84 | + <groupId>org.projectlombok</groupId> | |
| 85 | + <artifactId>lombok</artifactId> | |
| 86 | + <optional>true</optional> | |
| 87 | + </dependency> | |
| 88 | + | |
| 89 | + <dependency> | |
| 90 | + <groupId>org.springframework.boot</groupId> | |
| 91 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 92 | + <scope>test</scope> | |
| 93 | + </dependency> | |
| 94 | + </dependencies> | |
| 95 | + | |
| 96 | + <build> | |
| 97 | + <plugins> | |
| 98 | + <plugin> | |
| 99 | + <groupId>org.springframework.boot</groupId> | |
| 100 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
| 101 | + <configuration> | |
| 102 | + <excludes> | |
| 103 | + <exclude> | |
| 104 | + <groupId>org.projectlombok</groupId> | |
| 105 | + <artifactId>lombok</artifactId> | |
| 106 | + </exclude> | |
| 107 | + </excludes> | |
| 108 | + </configuration> | |
| 109 | + </plugin> | |
| 110 | + <plugin> | |
| 111 | + <groupId>org.apache.maven.plugins</groupId> | |
| 112 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 113 | + <configuration> | |
| 114 | + <environmentVariables> | |
| 115 | + <DB_HOST>${env.DB_HOST}</DB_HOST> | |
| 116 | + <DB_PORT>${env.DB_PORT}</DB_PORT> | |
| 117 | + <DB_USER>${env.DB_USER}</DB_USER> | |
| 118 | + <DB_PASSWORD>${env.DB_PASSWORD}</DB_PASSWORD> | |
| 119 | + <DB_SCHEMA>${env.DB_SCHEMA}</DB_SCHEMA> | |
| 120 | + <JWT_SECRET>${env.JWT_SECRET}</JWT_SECRET> | |
| 121 | + </environmentVariables> | |
| 122 | + </configuration> | |
| 123 | + </plugin> | |
| 124 | + </plugins> | |
| 125 | + </build> | |
| 126 | +</project> | ... | ... |
backend/src/main/java/com/xly/erp/Application.java
0 → 100644
| 1 | +package com.xly.erp; | |
| 2 | + | |
| 3 | +import org.mybatis.spring.annotation.MapperScan; | |
| 4 | +import org.springframework.boot.SpringApplication; | |
| 5 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 6 | + | |
| 7 | +@SpringBootApplication | |
| 8 | +@MapperScan("com.xly.erp.module.*.mapper") | |
| 9 | +public class Application { | |
| 10 | + public static void main(String[] args) { | |
| 11 | + SpringApplication.run(Application.class, args); | |
| 12 | + } | |
| 13 | +} | ... | ... |
backend/src/main/resources/application-test.yml
0 → 100644
| 1 | +spring: | |
| 2 | + datasource: | |
| 3 | + url: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true | |
| 4 | + username: ${DB_USER} | |
| 5 | + password: ${DB_PASSWORD} | |
| 6 | + flyway: | |
| 7 | + enabled: true | |
| 8 | + locations: filesystem:../sql/migrations | |
| 9 | + | |
| 10 | +jwt: | |
| 11 | + secret: ${JWT_SECRET:test-secret-please-replace-with-256bit-random-string-xxxxxxx} | |
| 12 | + ttl-sec: 7200 | |
| 13 | + | |
| 14 | +logging: | |
| 15 | + level: | |
| 16 | + root: WARN | |
| 17 | + com.xly.erp: DEBUG | |
| 18 | + com.zaxxer.hikari: WARN | ... | ... |
backend/src/main/resources/application.yml
0 → 100644
| 1 | +server: | |
| 2 | + port: 9090 | |
| 3 | + | |
| 4 | +spring: | |
| 5 | + application: | |
| 6 | + name: xly-erp-backend | |
| 7 | + datasource: | |
| 8 | + driver-class-name: com.mysql.cj.jdbc.Driver | |
| 9 | + url: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true | |
| 10 | + username: ${DB_USER} | |
| 11 | + password: ${DB_PASSWORD} | |
| 12 | + flyway: | |
| 13 | + enabled: true | |
| 14 | + locations: filesystem:../sql/migrations | |
| 15 | + baseline-on-migrate: true | |
| 16 | + baseline-version: 0 | |
| 17 | + validate-on-migrate: true | |
| 18 | + | |
| 19 | +mybatis-plus: | |
| 20 | + configuration: | |
| 21 | + map-underscore-to-camel-case: false | |
| 22 | + log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl | |
| 23 | + global-config: | |
| 24 | + db-config: | |
| 25 | + id-type: auto | |
| 26 | + | |
| 27 | +jwt: | |
| 28 | + secret: ${JWT_SECRET} | |
| 29 | + ttl-sec: 7200 | |
| 30 | + | |
| 31 | +logging: | |
| 32 | + level: | |
| 33 | + root: INFO | |
| 34 | + com.xly.erp: DEBUG | ... | ... |
backend/src/main/resources/logback-spring.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<configuration> | |
| 3 | + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | |
| 4 | + <encoder> | |
| 5 | + <pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern> | |
| 6 | + </encoder> | |
| 7 | + </appender> | |
| 8 | + | |
| 9 | + <root level="INFO"> | |
| 10 | + <appender-ref ref="CONSOLE"/> | |
| 11 | + </root> | |
| 12 | + | |
| 13 | + <logger name="com.xly.erp" level="DEBUG"/> | |
| 14 | +</configuration> | ... | ... |
backend/src/test/java/com/xly/erp/ApplicationContextTest.java
0 → 100644
| 1 | +package com.xly.erp; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Test; | |
| 4 | +import org.springframework.boot.test.context.SpringBootTest; | |
| 5 | +import org.springframework.context.ApplicationContext; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | + | |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * REQ-USR-001 — Boot smoke test: | |
| 12 | + * verifies Spring Boot context starts and Flyway has applied V1 against the | |
| 13 | + * MySQL schema configured via .env.local (DB_HOST/DB_PORT/DB_USER/DB_PASSWORD/DB_SCHEMA). | |
| 14 | + */ | |
| 15 | +@SpringBootTest | |
| 16 | +@org.springframework.test.context.ActiveProfiles("test") | |
| 17 | +class ApplicationContextTest { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + private ApplicationContext ctx; | |
| 21 | + | |
| 22 | + @Test | |
| 23 | + void contextLoads() { | |
| 24 | + assertNotNull(ctx, "Spring ApplicationContext should be initialised"); | |
| 25 | + } | |
| 26 | +} | ... | ... |