create-spring-boot-kotlin-project
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Spring Boot Kotlin project prompt
创建Spring Boot Kotlin项目提示
-
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项目模板中的和
artifactIdpackageName -
如果你需要更新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-kotlin} \
-d bootVersion=3.4.5 \
-d dependencies=configuration-processor,webflux,data-r2dbc,postgresql,data-redis-reactive,data-mongodb-reactive,validation,cache,testcontainers \
-d javaVersion=21 \
-d language=kotlin \
-d packageName=com.example \
-d packaging=jar \
-d type=gradle-project-kotlin \
-o starter.zip- 在终端运行以下命令下载Spring Boot项目模板
shell
curl https://start.spring.io/starter.zip \
-d artifactId=${input:projectName:demo-kotlin} \
-d bootVersion=3.4.5 \
-d dependencies=configuration-processor,webflux,data-r2dbc,postgresql,data-redis-reactive,data-mongodb-reactive,validation,cache,testcontainers \
-d javaVersion=21 \
-d language=kotlin \
-d packageName=com.example \
-d packaging=jar \
-d type=gradle-project-kotlin \
-o starter.zipUnzip the downloaded file
解压下载的文件
- Run following command in terminal to unzip the downloaded file
shell
unzip starter.zip -d ./${input:projectName:demo-kotlin}- 在终端运行以下命令解压下载的文件
shell
unzip starter.zip -d ./${input:projectName:demo-kotlin}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.zipUnzip the downloaded file
解压下载的文件
- Run following command in terminal to unzip the downloaded file
shell
unzip starter.zip -d ./${input:projectName:demo-kotlin}- 在终端运行以下命令解压下载的文件
shell
unzip starter.zip -d ./${input:projectName:demo-kotlin}Add additional dependencies
添加额外依赖
- Insert and
springdoc-openapi-starter-webmvc-uidependency intoarchunit-junit5filebuild.gradle.kts
gradle
dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.6")
testImplementation("com.tngtech.archunit:archunit-junit5:1.2.1")
}- Insert SpringDoc configurations into file
application.properties
properties
undefined- 将和
springdoc-openapi-starter-webmvc-ui依赖插入到archunit-junit5文件中build.gradle.kts
gradle
dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.6")
testImplementation("com.tngtech.archunit:archunit-junit5:1.2.1")
}- 将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 R2DBC configurations into `application.properties` file
```propertiesspring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=rootroot
- 将R2DBC配置插入到`application.properties`文件中
```propertiesR2DBC configurations
R2DBC configurations
spring.r2dbc.url=r2dbc:postgresql://localhost:5432/postgres
spring.r2dbc.username=postgres
spring.r2dbc.password=rootroot
spring.sql.init.mode=always
spring.sql.init.platform=postgres
spring.sql.init.continue-on-error=true
- Insert MongoDB configurations into `application.properties` file
```propertiesspring.r2dbc.url=r2dbc:postgresql://localhost:5432/postgres
spring.r2dbc.username=postgres
spring.r2dbc.password=rootroot
spring.sql.init.mode=always
spring.sql.init.platform=postgres
spring.sql.init.continue-on-error=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
- Create `docker-compose.yaml` at project root and add following services: `redis:6`, `postgresql:17` and `mongo:8`.
- redis service should have
- password `rootroot`
- mapping port 6379 to 6379
- mounting volume `./redis_data` to `/data`
- postgresql service should have
- password `rootroot`
- mapping port 5432 to 5432
- mounting volume `./postgres_data` to `/var/lib/postgresql/data`
- mongo service should have
- initdb root username `root`
- initdb root password `rootroot`
- mapping port 27017 to 27017
- mounting volume `./mongo_data` to `/data/db`
- Insert `redis_data`, `postgres_data` and `mongo_data` directories in `.gitignore` file
- Run gradle clean test command to check if the project is working
```shell
./gradlew clean test- (Optional) to start the services,
docker-compose up -dto run the Spring Boot project,./gradlew spring-boot:runto stop the services.docker-compose rm -sf
Let's do this step by step.
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
- 在项目根目录创建`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`
- mongo服务应包含
- 初始化数据库根用户名`root`
- 初始化数据库根密码`rootroot`
- 端口映射27017到27017
- 卷挂载`./mongo_data`到`/data/db`
- 将`redis_data`、`postgres_data`和`mongo_data`目录添加到`.gitignore`文件中
- 运行gradle clean test命令检查项目是否正常工作
```shell
./gradlew clean test- (可选)运行启动服务,
docker-compose up -d启动Spring Boot项目,./gradlew spring-boot:run停止服务。docker-compose rm -sf
让我们一步步来完成这些操作。