Commit 1ad70c5f2825d4fd4d3b5ad6e684ab3fe9f6e601
1 parent
f20b8d26
feat(usr): 后端工程骨架 (Spring Boot 3.3 + MyBatis-Plus + Flyway) REQ-USR-001
Showing
6 changed files
with
251 additions
and
0 deletions
backend/.gitignore
0 → 100644
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.5</version> | ||
| 11 | + <relativePath/> | ||
| 12 | + </parent> | ||
| 13 | + | ||
| 14 | + <groupId>com.xly</groupId> | ||
| 15 | + <artifactId>test4-backend</artifactId> | ||
| 16 | + <version>0.0.1-SNAPSHOT</version> | ||
| 17 | + <name>test4-backend</name> | ||
| 18 | + <description>小羚羊 ERP 后端</description> | ||
| 19 | + | ||
| 20 | + <properties> | ||
| 21 | + <java.version>21</java.version> | ||
| 22 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 23 | + <mybatis-plus.version>3.5.7</mybatis-plus.version> | ||
| 24 | + <mapstruct.version>1.5.5.Final</mapstruct.version> | ||
| 25 | + <lombok.version>1.18.32</lombok.version> | ||
| 26 | + <lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version> | ||
| 27 | + <jjwt.version>0.12.5</jjwt.version> | ||
| 28 | + <springdoc.version>2.6.0</springdoc.version> | ||
| 29 | + </properties> | ||
| 30 | + | ||
| 31 | + <dependencies> | ||
| 32 | + <dependency> | ||
| 33 | + <groupId>org.springframework.boot</groupId> | ||
| 34 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 35 | + </dependency> | ||
| 36 | + <dependency> | ||
| 37 | + <groupId>org.springframework.boot</groupId> | ||
| 38 | + <artifactId>spring-boot-starter-security</artifactId> | ||
| 39 | + </dependency> | ||
| 40 | + <dependency> | ||
| 41 | + <groupId>org.springframework.boot</groupId> | ||
| 42 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 43 | + </dependency> | ||
| 44 | + | ||
| 45 | + <dependency> | ||
| 46 | + <groupId>com.baomidou</groupId> | ||
| 47 | + <artifactId>mybatis-plus-spring-boot3-starter</artifactId> | ||
| 48 | + <version>${mybatis-plus.version}</version> | ||
| 49 | + </dependency> | ||
| 50 | + | ||
| 51 | + <dependency> | ||
| 52 | + <groupId>org.flywaydb</groupId> | ||
| 53 | + <artifactId>flyway-core</artifactId> | ||
| 54 | + </dependency> | ||
| 55 | + <dependency> | ||
| 56 | + <groupId>org.flywaydb</groupId> | ||
| 57 | + <artifactId>flyway-mysql</artifactId> | ||
| 58 | + </dependency> | ||
| 59 | + | ||
| 60 | + <dependency> | ||
| 61 | + <groupId>com.mysql</groupId> | ||
| 62 | + <artifactId>mysql-connector-j</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.mapstruct</groupId> | ||
| 85 | + <artifactId>mapstruct</artifactId> | ||
| 86 | + <version>${mapstruct.version}</version> | ||
| 87 | + </dependency> | ||
| 88 | + <dependency> | ||
| 89 | + <groupId>org.projectlombok</groupId> | ||
| 90 | + <artifactId>lombok</artifactId> | ||
| 91 | + <version>${lombok.version}</version> | ||
| 92 | + <scope>provided</scope> | ||
| 93 | + </dependency> | ||
| 94 | + | ||
| 95 | + <dependency> | ||
| 96 | + <groupId>org.springdoc</groupId> | ||
| 97 | + <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
| 98 | + <version>${springdoc.version}</version> | ||
| 99 | + </dependency> | ||
| 100 | + | ||
| 101 | + <dependency> | ||
| 102 | + <groupId>org.springframework.boot</groupId> | ||
| 103 | + <artifactId>spring-boot-starter-test</artifactId> | ||
| 104 | + <scope>test</scope> | ||
| 105 | + </dependency> | ||
| 106 | + <dependency> | ||
| 107 | + <groupId>org.springframework.security</groupId> | ||
| 108 | + <artifactId>spring-security-test</artifactId> | ||
| 109 | + <scope>test</scope> | ||
| 110 | + </dependency> | ||
| 111 | + </dependencies> | ||
| 112 | + | ||
| 113 | + <build> | ||
| 114 | + <finalName>test4-backend</finalName> | ||
| 115 | + <plugins> | ||
| 116 | + <plugin> | ||
| 117 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 118 | + <artifactId>maven-compiler-plugin</artifactId> | ||
| 119 | + <configuration> | ||
| 120 | + <source>21</source> | ||
| 121 | + <target>21</target> | ||
| 122 | + <annotationProcessorPaths> | ||
| 123 | + <path> | ||
| 124 | + <groupId>org.projectlombok</groupId> | ||
| 125 | + <artifactId>lombok</artifactId> | ||
| 126 | + <version>${lombok.version}</version> | ||
| 127 | + </path> | ||
| 128 | + <path> | ||
| 129 | + <groupId>org.mapstruct</groupId> | ||
| 130 | + <artifactId>mapstruct-processor</artifactId> | ||
| 131 | + <version>${mapstruct.version}</version> | ||
| 132 | + </path> | ||
| 133 | + <path> | ||
| 134 | + <groupId>org.projectlombok</groupId> | ||
| 135 | + <artifactId>lombok-mapstruct-binding</artifactId> | ||
| 136 | + <version>${lombok-mapstruct-binding.version}</version> | ||
| 137 | + </path> | ||
| 138 | + </annotationProcessorPaths> | ||
| 139 | + </configuration> | ||
| 140 | + </plugin> | ||
| 141 | + <plugin> | ||
| 142 | + <groupId>org.springframework.boot</groupId> | ||
| 143 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 144 | + <configuration> | ||
| 145 | + <excludes> | ||
| 146 | + <exclude> | ||
| 147 | + <groupId>org.projectlombok</groupId> | ||
| 148 | + <artifactId>lombok</artifactId> | ||
| 149 | + </exclude> | ||
| 150 | + </excludes> | ||
| 151 | + </configuration> | ||
| 152 | + </plugin> | ||
| 153 | + <plugin> | ||
| 154 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 155 | + <artifactId>maven-surefire-plugin</artifactId> | ||
| 156 | + <configuration> | ||
| 157 | + <includes> | ||
| 158 | + <include>**/*Test.java</include> | ||
| 159 | + <include>**/*IT.java</include> | ||
| 160 | + </includes> | ||
| 161 | + </configuration> | ||
| 162 | + </plugin> | ||
| 163 | + </plugins> | ||
| 164 | + </build> | ||
| 165 | +</project> |
backend/src/main/java/com/xly/test4/Application.java
0 → 100644
| 1 | +package com.xly.test4; | ||
| 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.test4.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-dev.yml
0 → 100644
backend/src/main/resources/application.yml
0 → 100644
| 1 | +spring: | ||
| 2 | + application: | ||
| 3 | + name: test4-backend | ||
| 4 | + profiles: | ||
| 5 | + active: dev | ||
| 6 | + config: | ||
| 7 | + import: optional:file:../.env.local[.properties] | ||
| 8 | + datasource: | ||
| 9 | + url: jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&useSSL=false | ||
| 10 | + username: ${DB_USER} | ||
| 11 | + password: ${DB_PASSWORD} | ||
| 12 | + driver-class-name: com.mysql.cj.jdbc.Driver | ||
| 13 | + flyway: | ||
| 14 | + enabled: true | ||
| 15 | + locations: filesystem:../sql/migrations | ||
| 16 | + baseline-on-migrate: false | ||
| 17 | + | ||
| 18 | +server: | ||
| 19 | + port: 8080 | ||
| 20 | + | ||
| 21 | +mybatis-plus: | ||
| 22 | + mapper-locations: classpath:mapper/**/*.xml | ||
| 23 | + global-config: | ||
| 24 | + db-config: | ||
| 25 | + id-type: AUTO | ||
| 26 | + configuration: | ||
| 27 | + map-underscore-to-camel-case: false | ||
| 28 | + | ||
| 29 | +app: | ||
| 30 | + security: | ||
| 31 | + default-password: "666666" | ||
| 32 | + max-login-fail: 5 | ||
| 33 | + lock-minutes: 30 | ||
| 34 | + jwt: | ||
| 35 | + secret: ${JWT_SECRET} | ||
| 36 | + access-ttl-hours: 24 | ||
| 37 | + | ||
| 38 | +springdoc: | ||
| 39 | + api-docs: | ||
| 40 | + path: /v3/api-docs | ||
| 41 | + swagger-ui: | ||
| 42 | + path: /swagger-ui.html |
backend/src/test/java/com/xly/test4/ApplicationContextIT.java
0 → 100644
| 1 | +package com.xly.test4; | ||
| 2 | + | ||
| 3 | +import org.junit.jupiter.api.Test; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.boot.test.context.SpringBootTest; | ||
| 6 | +import org.springframework.context.ApplicationContext; | ||
| 7 | + | ||
| 8 | +import static org.assertj.core.api.Assertions.assertThat; | ||
| 9 | + | ||
| 10 | +@SpringBootTest | ||
| 11 | +class ApplicationContextIT { | ||
| 12 | + | ||
| 13 | + @Autowired | ||
| 14 | + private ApplicationContext context; | ||
| 15 | + | ||
| 16 | + @Test | ||
| 17 | + void contextLoads() { | ||
| 18 | + assertThat(context).isNotNull(); | ||
| 19 | + assertThat(context.getBean(Application.class)).isNotNull(); | ||
| 20 | + } | ||
| 21 | +} |