[2025-05-27] 添加新项目快速初始化教程
All checks were successful
Publish to Confluence / confluence (push) Successful in 1m15s

This commit is contained in:
liuxiaohua 2025-05-27 10:47:04 +08:00
parent d0545d80ff
commit 070acb0251

View File

@ -0,0 +1,253 @@
<!-- Space: qifu -->
<!-- Parent: 后端技术&知识&规范 -->
<!-- Parent: 技术方案 -->
<!-- Parent: 基建 -->
<!-- Parent: 00-基础组件 -->
<!-- Title: 20250527-新项目快速初始化教程 -->
<!-- Macro: :anchor\((.*)\):
Template: ac:anchor
Anchor: ${1} -->
<!-- Macro: \!\[.*\]\((.+)\)\<\!\-\- width=(.*) \-\-\>
Template: ac:image
Url: ${1}
Width: ${2} -->
<!-- Macro: \<\!\-\- :toc: \-\-\>
Template: ac:toc
Printable: 'false'
MinLevel: 2
MaxLevel: 4 -->
<!-- Include: 杂项/声明文件.md -->
<!-- :toc: -->
# 新项目快速初始化教程
## 使用 Maven Archetype 初始化项目(建议)
### 前置配置步骤
#### 添加私服骨架配置文件
- 建议在本地仓库根目录添加
- 存在则增量添加 `archetype`
```xml
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<archetypes>
<archetype>
<groupId>com.yuanmeng.engine</groupId>
<artifactId>engine-archetype-web</artifactId>
<version>2.0.0-SNAPSHOT</version>
<description>Parent pom providing dependency and plugin management for applications built with Maven</description>
</archetype>
</archetypes>
</archetype-catalog>
```
### IDEA 新建项目
#### IDEA 点击 New Project 创建新项目
![](https://picture.texous.cn/blog/20250527100709361.png)
#### 选择 Maven Archetype 项目
![](https://picture.texous.cn/blog/20250527100806729.png)
#### 管理添加前置步骤创建的Catalog
![](https://picture.texous.cn/blog/20250527101058992.png)
- 点击 `Manage catalogs`
- 1: 点击添加
- 2: 点击 `文件夹图标` 选择 `archetype-catalog.xml` 所在目录
- 3: 选择该文件夹
- 4: 点击 Add 添加
#### 填充信息创建项目
- ![](https://picture.texous.cn/blog/20250527101544423.png)
- 1: 项目名称
- 2: 选择刚刚添加的 `catalog`
- 3: 选择骨架项目 `engine-archetype-web`
- 4: 配置服务启动类前缀
- 5: 配置服务基础包名
- 6: 开始创建
#### 启动项目
- 等待项目创建完成
- 启动类启动
- 使用 `test > resources > http > TestUserController.http` 测试前两个接口
- ![](https://picture.texous.cn/blog/20250527104138665.png)
------
## 手工方式初始化项目
### 新建项目
#### 项目结构
- qifu-saas-xxx
- qifu-saas-xxx-client
- qifu-saas-xxx-service
### 引入需要的功能包
#### qifu-saas-xxx > pom.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yuanmeng.qifu</groupId>
<artifactId>qifu-saas-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>qifu-saas-xxx</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>qifu-saas-xxx</name>
<modules>
<module>qifu-saas-xxx-client</module>
<module>qifu-saas-xxx-service</module>
</modules>
<properties>
<!-- 开发版本管理 -->
<revision>0.0.1-SNAPSHOT</revision>
<qifu.saas.xxx.client.version>0.0.1-SNAPSHOT</qifu.saas.xxx.client.version>
</properties>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<!-- 发布版本管理 -->
<revision>0.0.1</revision>
<qifu.saas.xxx.client.version>0.0.1</qifu.saas.xxx.client.version>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.yuanmeng.qifu</groupId>
<artifactId>qifu-saas-xxx-client</artifactId>
<version>${qifu.saas.xxx.client.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
```
#### qifu-saas-xxx-client > pom.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yuanmeng.qifu</groupId>
<artifactId>qifu-saas-xxx</artifactId>
<version>${revision}</version>
</parent>
<artifactId>qifu-saas-xxx-client</artifactId>
<dependencies>
<dependency>
<groupId>com.yuanmeng.engine</groupId>
<artifactId>engine-starter-feign</artifactId>
</dependency>
</dependencies>
</project>
```
#### qifu-saas-xxx-service > pom.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yuanmeng.qifu</groupId>
<artifactId>qifu-saas-xxx</artifactId>
<version>${revision}</version>
</parent>
<artifactId>qifu-saas-xxx-service</artifactId>
<dependencies>
<dependency>
<groupId>com.yuanmeng.qifu</groupId>
<artifactId>qifu-saas-xxx-client</artifactId>
</dependency>
<dependency>
<groupId>com.yuanmeng.engine</groupId>
<artifactId>engine-starter-web</artifactId>
</dependency>
</dependencies>
</project>
```
### 编写启动类
```java
@EnableFeignClients(basePackages = {"com.yuanmeng.*"})
@EnableDiscoveryClient
@SpringBootApplication
public class QifuSaasEgApplication {
public static void main(String[] args) {
SpringApplication.run(QifuSaasEgApplication.class, args);
}
}
```
### 编写配置文件
- `bootstrap.yml`
```yaml
server:
port: 10000
spring:
application:
name: qifu-saas-xxx
cloud:
# nacos 配置本地不需要,别的环境会使用运维版本,不需要自己维护
nacos:
discovery:
namespace: qifu-develop
server-addr: @discovery.server-addr@
username: @discovery.username@
password: @discovery.password@
register-enabled: false
ip: ${spring.application.name}
# config:
# namespace: @config.namespace@
# server-addr: @discovery.server-addr@
# username: @discovery.username@
# password: @discovery.password@
# file-extension: yml
# config-retry-time: 30000
```
### 启动测试