create-spring-boot-java-project
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Spring Boot Java project prompt
创建Spring Boot Java项目指引
-
Please make sure you have the following software installed on your system:
- Java 21
- Docker
- Docker Compose
-
If you need to custom the project name, please change theand the
artifactIdin download-spring-boot-project-templatepackageName -
If you need to update the Spring Boot version, please change thein download-spring-boot-project-template
bootVersion
-
请确保你的系统中已安装以下软件:
- Java 21
- Docker
- Docker Compose
-
如果你需要更新Spring Boot版本,请修改下载Spring Boot项目模板中的
bootVersion
Check Java version
检查Java版本
- Run following command in terminal and check the version of Java
shell
java -version- 在终端运行以下命令,检查Java版本
shell
java -versionDownload Spring Boot project template
下载Spring Boot项目模板
- Run following command in terminal to download a Spring Boot project template
shell
curl https://start.spring.io/starter.zip \
-d artifactId=${input:projectName:demo-java} \
-d bootVersion=3.4.5 \
-d dependencies=lombok,configuration-processor,web,data-jpa,postgresql,data-redis,data-mongodb,validation,cache,testcontainers \
-d javaVersion=21 \
-d packageName=com.example \
-d packaging=jar \
-d type=maven-project \
-o starter.zip- 在终端运行以下命令下载Spring Boot项目模板
shell
curl https://start.spring.io/starter.zip \
-d artifactId=${input:projectName:demo-java} \
-d bootVersion=3.4.5 \
-d dependencies=lombok,configuration-processor,web,data-jpa,postgresql,data-redis,data-mongodb,validation,cache,testcontainers \
-d javaVersion=21 \
-d packageName=com.example \
-d packaging=jar \
-d type=maven-project \
-o starter.zipUnzip the downloaded file
解压下载的文件
- Run following command in terminal to unzip the downloaded file
shell
unzip starter.zip -d ./${input:projectName:demo-java}- 在终端运行以下命令解压下载的文件
shell
unzip starter.zip -d ./${input:projectName:demo-java}Remove the downloaded zip file
删除下载的压缩文件
- Run following command in terminal to delete the downloaded zip file
shell
rm -f starter.zip- 在终端运行以下命令删除下载的压缩文件
shell
rm -f starter.zipChange directory to the project root
切换到项目根目录
- Run following command in terminal to change directory to the project root
shell
cd ${input:projectName:demo-java}- 在终端运行以下命令切换到项目根目录
shell
cd ${input:projectName:demo-java}Add additional dependencies
添加额外依赖
- Insert and
springdoc-openapi-starter-webmvc-uidependency intoarchunit-junit5filepom.xml
xml
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>- 将和
springdoc-openapi-starter-webmvc-ui依赖插入到archunit-junit5文件中pom.xml
xml
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>Add SpringDoc, Redis, JPA and MongoDB configurations
添加SpringDoc、Redis、JPA和MongoDB配置
- Insert SpringDoc configurations into file
application.properties
properties
undefined- 将SpringDoc配置插入到文件中
application.properties
properties
undefinedSpringDoc configurations
SpringDoc configurations
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
- Insert Redis configurations into `application.properties` file
```propertiesspringdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
- 将Redis配置插入到`application.properties`文件中
```propertiesRedis configurations
Redis configurations
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=rootroot
- Insert JPA configurations into `application.properties` file
```propertiesspring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=rootroot
- 将JPA配置插入到`application.properties`文件中
```propertiesJPA configurations
JPA configurations
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=rootroot
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
- Insert MongoDB configurations into `application.properties` file
```propertiesspring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=rootroot
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
- 将MongoDB配置插入到`application.properties`文件中
```propertiesMongoDB configurations
MongoDB configurations
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=root
spring.data.mongodb.password=rootroot
spring.data.mongodb.database=test
undefinedspring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=root
spring.data.mongodb.password=rootroot
spring.data.mongodb.database=test
undefinedAdd docker-compose.yaml
with Redis, PostgreSQL and MongoDB services
docker-compose.yaml添加包含Redis、PostgreSQL和MongoDB服务的docker-compose.yaml
docker-compose.yaml-
Createat project root and add following services:
docker-compose.yaml,redis:6andpostgresql:17.mongo:8- redis service should have
- password
rootroot - mapping port 6379 to 6379
- mounting volume to
./redis_data/data
- password
- postgresql service should have
- password
rootroot - mapping port 5432 to 5432
- mounting volume to
./postgres_data/var/lib/postgresql/data
- password
- mongo service should have
- initdb root username
root - initdb root password
rootroot - mapping port 27017 to 27017
- mounting volume to
./mongo_data/data/db
- initdb root username
- redis service should have
-
在项目根目录创建,并添加以下服务:
docker-compose.yaml、redis:6和postgresql:17。mongo:8- Redis服务需包含:
- 密码
rootroot - 端口6379映射到6379
- 卷挂载到
./redis_data/data
- 密码
- PostgreSQL服务需包含:
- 密码
rootroot - 端口5432映射到5432
- 卷挂载到
./postgres_data/var/lib/postgresql/data
- 密码
- MongoDB服务需包含:
- 初始化根用户名
root - 初始化根密码
rootroot - 端口27017映射到27017
- 卷挂载到
./mongo_data/data/db
- 初始化根用户名
- Redis服务需包含:
Add .gitignore
file
.gitignore添加.gitignore
文件
.gitignore- Insert ,
redis_dataandpostgres_datadirectories inmongo_datafile.gitignore
- 在文件中添加
.gitignore、redis_data和postgres_data目录mongo_data
Run Maven test command
运行Maven测试命令
- Run maven clean test command to check if the project is working
shell
./mvnw clean test- 运行Maven clean test命令检查项目是否正常工作
shell
./mvnw clean testRun Maven run command (Optional)
运行Maven启动命令(可选)
- (Optional) to start the services,
docker-compose up -dto run the Spring Boot project,./mvnw spring-boot:runto stop the services.docker-compose rm -sf
- (可选)执行启动服务,
docker-compose up -d运行Spring Boot项目,./mvnw spring-boot:run停止服务。docker-compose rm -sf