spring-boot-project-creator by giuseppe-trisciuoglio/developer-kit
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-project-creator使用 Spring Initializr API 从零开始生成一个完全配置好的 Spring Boot 项目。该技能引导用户选择项目参数、选择架构风格(DDD 或分层)、配置数据存储,并为本地开发设置 Docker Compose。最终生成一个具备标准化结构、依赖管理和配置、可直接构建的项目。
开始之前,请确保已安装以下工具:
按照以下步骤创建一个新的 Spring Boot 项目。
使用 AskUserQuestion 向用户询问以下项目参数。提供合理的默认值:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 参数 | 默认值 | 选项 |
|---|
| Group ID | com.example | 任何有效的 Java 包名 |
| Artifact ID | demo | Kebab-case 标识符 |
| Package Name | 与 Group ID 相同 | 有效的 Java 包名 |
| Spring Boot 版本 | 3.4.5 | 3.4.x, 4.0.x(请查看 start.spring.io 获取最新版本) |
| Java 版本 | 21 | 17, 21 |
| 架构 | 用户选择 | DDD 或 Layered |
| Docker 服务 | 用户选择 | PostgreSQL, Redis, MongoDB(多选) |
| 构建工具 | maven | maven, gradle |
使用 curl 从 start.spring.io 下载项目脚手架。
基础依赖(始终包含):
web — Spring Web MVCvalidation — Jakarta Bean Validationdata-jpa — Spring Data JPAtestcontainers — Testcontainers 支持条件依赖(基于 Docker 服务选择):
postgresqldata-redisdata-mongodb# 仅包含 PostgreSQL 的 Spring Boot 3.4.5 示例
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d language=java \
-d bootVersion=3.4.5 \
-d groupId=com.example \
-d artifactId=demo \
-d packageName=com.example \
-d javaVersion=21 \
-d packaging=jar \
-d dependencies=web,data-jpa,postgresql,validation,testcontainers \
-o starter.zip
unzip -o starter.zip -d ./demo
rm starter.zip
cd demo
编辑 pom.xml 以添加 SpringDoc OpenAPI 和用于架构测试的 ArchUnit。
<!-- SpringDoc OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.15</version>
</dependency>
<!-- ArchUnit for architecture tests -->
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.4.1</version>
<scope>test</scope>
</dependency>
根据用户的选择,在 src/main/java/<packagePath>/ 下创建包结构。
src/main/java/com/example/
├── controller/ # REST 控制器 (@RestController)
├── service/ # 业务逻辑 (@Service)
├── repository/ # 数据访问 (@Repository, Spring Data 接口)
├── model/ # JPA 实体 (@Entity)
│ └── dto/ # 请求/响应 DTOs (Java records)
├── config/ # 配置类 (@Configuration)
└── exception/ # 自定义异常和 @ControllerAdvice
为每一层创建占位类:
@RestControllerAdvicesrc/main/java/com/example/
├── domain/ # 核心领域(无框架依赖)
│ ├── model/ # 实体、值对象、聚合
│ ├── repository/ # 仓库接口(端口)
│ └── exception/ # 领域异常
├── application/ # 用例 / 应用服务
│ ├── service/ # @Service 编排
│ └── dto/ # 输入/输出 DTOs (records)
├── infrastructure/ # 外部适配器
│ ├── persistence/ # JPA 实体,Spring Data 仓库
│ └── config/ # Spring @Configuration
└── presentation/ # REST API 层
├── controller/ # @RestController
└── exception/ # @RestControllerAdvice
为每一层创建占位类:
@RestControllerAdvice使用选定的服务创建 src/main/resources/application.properties。
始终包含:
# Application
spring.application.name=${artifactId}
# SpringDoc OpenAPI
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
如果选择了 PostgreSQL:
# PostgreSQL / JPA
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/${POSTGRES_DB:postgres}
spring.datasource.username=${POSTGRES_USER:postgres}
spring.datasource.password=${POSTGRES_PASSWORD:changeme}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
如果选择了 Redis:
# Redis
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=${REDIS_PASSWORD:changeme}
如果选择了 MongoDB:
# MongoDB
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=${MONGO_USER:root}
spring.data.mongodb.password=${MONGO_PASSWORD:changeme}
spring.data.mongodb.database=${MONGO_DB:test}
在项目根目录创建 docker-compose.yaml,仅包含用户选择的服务。
services:
# 如果选择了 PostgreSQL 则包含此项
postgresql:
image: postgres:17
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
POSTGRES_DB: ${POSTGRES_DB:-postgres}
volumes:
- ./postgres_data:/var/lib/postgresql/data
# 如果选择了 Redis 则包含此项
redis:
image: redis:7
ports:
- "6379:6379"
command: redis-server --requirepass ${REDIS_PASSWORD:-changeme}
volumes:
- ./redis_data:/data
# 如果选择了 MongoDB 则包含此项
mongodb:
image: mongo:8
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-changeme}
volumes:
- ./mongo_data:/data/db
.env 文件在项目根目录创建一个 .env 文件,包含用于本地开发的默认凭据:
# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changeme
POSTGRES_DB=postgres
# Redis
REDIS_PASSWORD=changeme
# MongoDB
MONGO_USER=root
MONGO_PASSWORD=changeme
MONGO_DB=test
仅包含用户选择的服务的变量。Docker Compose 会自动加载此文件。
将 Docker Compose 卷目录和 .env 文件追加到 .gitignore:
# Docker Compose
.env
postgres_data/
redis_data/
mongo_data/
运行 Maven 构建以确认项目可以编译且测试通过:
./mvnw clean verify
如果构建成功,通知用户。如果失败,请在继续之前诊断并修复问题。
显示已创建项目的摘要:
项目创建成功
项目标识: <artifactId>
Spring Boot: <version>
Java: <javaVersion>
架构: <DDD | Layered>
构建工具: Maven
Docker: <services list>
目录: ./<artifactId>/
后续步骤:
1. cd <artifactId>
2. docker compose up -d
3. ./mvnw spring-boot:run
4. 打开 http://localhost:8080/swagger-ui.html
传统的三层架构,关注点分离清晰:
| 层 | 包 | 职责 |
|---|---|---|
| 表示层 | controller/ | HTTP 端点,请求/响应映射 |
| 业务层 | service/ | 业务逻辑,事务管理 |
| 数据访问层 | repository/ | 通过 Spring Data 进行数据库操作 |
| 领域层 | model/ | JPA 实体和 DTOs |
最适合: 简单的 CRUD 应用、中小型服务、刚接触 Spring Boot 的团队。
具有六边形边界的领域驱动设计:
| 层 | 包 | 职责 |
|---|---|---|
| 领域层 | domain/ | 实体、值对象、领域服务(无框架依赖) |
| 应用层 | application/ | 用例、编排、DTO 映射 |
| 基础设施层 | infrastructure/ | JPA 适配器、外部集成、配置 |
| 表示层 | presentation/ | REST 控制器、错误处理 |
最适合: 复杂的业务领域、具有丰富逻辑的微服务、长期项目。
用户请求: "创建一个用于 REST API 的 Spring Boot 项目,使用 PostgreSQL"
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d bootVersion=3.4.5 \
-d groupId=com.example \
-d artifactId=my-api \
-d packageName=com.example.myapi \
-d javaVersion=21 \
-d dependencies=web,data-jpa,postgresql,validation,testcontainers \
-o starter.zip
结果:具有 controller/、service/、repository/、model/ 包、PostgreSQL Docker Compose 和 SpringDoc OpenAPI 的分层项目。
用户请求: "引导一个使用 DDD、PostgreSQL 和 Redis 的 Spring Boot 3 微服务"
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d bootVersion=3.4.5 \
-d groupId=com.acme \
-d artifactId=order-service \
-d packageName=com.acme.order \
-d javaVersion=21 \
-d dependencies=web,data-jpa,postgresql,data-redis,validation,testcontainers \
-o starter.zip
结果:具有 domain/、application/、infrastructure/、presentation/ 包、PostgreSQL + Redis Docker Compose 和 SpringDoc OpenAPI 的 DDD 项目。
domain/ 中不要使用 Spring 注解。docker-compose.yaml 中固定 Docker 镜像版本,以避免意外的破坏性更改。./mvnw clean verify,以确保一切都能编译且测试通过。.env 文件(被 git 忽略)加载 — 切勿将密钥提交到版本控制。spring.jpa.hibernate.ddl-auto=update 设置仅用于开发 — 在生产环境中使用 Flyway 或 Liquibase。每周安装次数
120
代码仓库
GitHub 星标数
173
首次出现
2026年2月28日
安全审计
安装于
codex104
gemini-cli104
github-copilot102
claude-code101
cursor99
amp99
Generates a fully configured Spring Boot project from scratch using the Spring Initializr API. The skill walks the user through selecting project parameters, choosing an architecture style (DDD or Layered), configuring data stores, and setting up Docker Compose for local development. The result is a build-ready project with standardized structure, dependency management, and configuration.
Before starting, ensure the following tools are installed:
Follow these steps to create a new Spring Boot project.
Ask the user for the following project parameters using AskUserQuestion. Provide sensible defaults:
| Parameter | Default | Options |
|---|---|---|
| Group ID | com.example | Any valid Java package name |
| Artifact ID | demo | Kebab-case identifier |
| Package Name | Same as Group ID | Valid Java package |
| Spring Boot Version | 3.4.5 | 3.4.x, 4.0.x (check start.spring.io for latest) |
Use curl to download the project scaffold from start.spring.io.
Base dependencies (always included):
web — Spring Web MVCvalidation — Jakarta Bean Validationdata-jpa — Spring Data JPAtestcontainers — Testcontainers supportConditional dependencies (based on Docker Services selection):
PostgreSQL selected → add postgresql
Redis selected → add data-redis
MongoDB selected → add data-mongodb
curl -s https://start.spring.io/starter.zip
-d type=maven-project
-d language=java
-d bootVersion=3.4.5
-d groupId=com.example
-d artifactId=demo
-d packageName=com.example
-d javaVersion=21
-d packaging=jar
-d dependencies=web,data-jpa,postgresql,validation,testcontainers
-o starter.zip
unzip -o starter.zip -d ./demo rm starter.zip cd demo
Edit pom.xml to add SpringDoc OpenAPI and ArchUnit for architectural testing.
<!-- SpringDoc OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.15</version>
</dependency>
<!-- ArchUnit for architecture tests -->
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.4.1</version>
<scope>test</scope>
</dependency>
Based on the user's choice, create the package structure under src/main/java/<packagePath>/.
src/main/java/com/example/
├── controller/ # REST controllers (@RestController)
├── service/ # Business logic (@Service)
├── repository/ # Data access (@Repository, Spring Data interfaces)
├── model/ # JPA entities (@Entity)
│ └── dto/ # Request/Response DTOs (Java records)
├── config/ # Configuration classes (@Configuration)
└── exception/ # Custom exceptions and @ControllerAdvice
Create placeholder classes for each layer:
@RestControllerAdvice with standard error handlingsrc/main/java/com/example/
├── domain/ # Core domain (framework-free)
│ ├── model/ # Entities, Value Objects, Aggregates
│ ├── repository/ # Repository interfaces (ports)
│ └── exception/ # Domain exceptions
├── application/ # Use cases / Application services
│ ├── service/ # @Service orchestration
│ └── dto/ # Input/Output DTOs (records)
├── infrastructure/ # External adapters
│ ├── persistence/ # JPA entities, Spring Data repos
│ └── config/ # Spring @Configuration
└── presentation/ # REST API layer
├── controller/ # @RestController
└── exception/ # @RestControllerAdvice
Create placeholder classes for each layer:
@RestControllerAdvice with standard error handlingCreate src/main/resources/application.properties with the selected services.
Always include:
# Application
spring.application.name=${artifactId}
# SpringDoc OpenAPI
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
If PostgreSQL is selected:
# PostgreSQL / JPA
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/${POSTGRES_DB:postgres}
spring.datasource.username=${POSTGRES_USER:postgres}
spring.datasource.password=${POSTGRES_PASSWORD:changeme}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
If Redis is selected:
# Redis
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=${REDIS_PASSWORD:changeme}
If MongoDB is selected:
# MongoDB
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=${MONGO_USER:root}
spring.data.mongodb.password=${MONGO_PASSWORD:changeme}
spring.data.mongodb.database=${MONGO_DB:test}
Create docker-compose.yaml at the project root with only the services the user selected.
services:
# Include if PostgreSQL selected
postgresql:
image: postgres:17
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
POSTGRES_DB: ${POSTGRES_DB:-postgres}
volumes:
- ./postgres_data:/var/lib/postgresql/data
# Include if Redis selected
redis:
image: redis:7
ports:
- "6379:6379"
command: redis-server --requirepass ${REDIS_PASSWORD:-changeme}
volumes:
- ./redis_data:/data
# Include if MongoDB selected
mongodb:
image: mongo:8
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-changeme}
volumes:
- ./mongo_data:/data/db
.env File for Docker ComposeCreate a .env file at the project root with default credentials for local development:
# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changeme
POSTGRES_DB=postgres
# Redis
REDIS_PASSWORD=changeme
# MongoDB
MONGO_USER=root
MONGO_PASSWORD=changeme
MONGO_DB=test
Include only the variables for the services the user selected. Docker Compose automatically loads this file.
Append Docker Compose volume directories and the .env file to .gitignore:
# Docker Compose
.env
postgres_data/
redis_data/
mongo_data/
Run the Maven build to confirm the project compiles and tests pass:
./mvnw clean verify
If the build succeeds, inform the user. If it fails, diagnose and fix the issue before proceeding.
Display a summary of the created project:
Project Created Successfully
Artifact: <artifactId>
Spring Boot: <version>
Java: <javaVersion>
Architecture: <DDD | Layered>
Build Tool: Maven
Docker: <services list>
Directory: ./<artifactId>/
Next Steps:
1. cd <artifactId>
2. docker compose up -d
3. ./mvnw spring-boot:run
4. Open http://localhost:8080/swagger-ui.html
Traditional three-tier architecture with clear separation of concerns:
| Layer | Package | Responsibility |
|---|---|---|
| Presentation | controller/ | HTTP endpoints, request/response mapping |
| Business | service/ | Business logic, transaction management |
| Data Access | repository/ | Database operations via Spring Data |
| Domain | model/ | JPA entities and DTOs |
Best for: Simple CRUD applications, small-to-medium services, teams new to Spring Boot.
Domain-Driven Design with hexagonal boundaries:
| Layer | Package | Responsibility |
|---|---|---|
| Domain | domain/ | Entities, value objects, domain services (framework-free) |
| Application | application/ | Use cases, orchestration, DTO mapping |
| Infrastructure | infrastructure/ | JPA adapters, external integrations, configuration |
| Presentation | presentation/ | REST controllers, error handling |
Best for: Complex business domains, microservices with rich logic, long-lived projects.
User request: "Create a Spring Boot project for a REST API with PostgreSQL"
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d bootVersion=3.4.5 \
-d groupId=com.example \
-d artifactId=my-api \
-d packageName=com.example.myapi \
-d javaVersion=21 \
-d dependencies=web,data-jpa,postgresql,validation,testcontainers \
-o starter.zip
Result: Layered project with controller/, service/, repository/, model/ packages, PostgreSQL Docker Compose, and SpringDoc OpenAPI.
User request: "Bootstrap a Spring Boot 3 microservice with DDD, PostgreSQL and Redis"
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d bootVersion=3.4.5 \
-d groupId=com.acme \
-d artifactId=order-service \
-d packageName=com.acme.order \
-d javaVersion=21 \
-d dependencies=web,data-jpa,postgresql,data-redis,validation,testcontainers \
-o starter.zip
Result: DDD project with domain/, application/, infrastructure/, presentation/ packages, PostgreSQL + Redis Docker Compose, and SpringDoc OpenAPI.
domain/.docker-compose.yaml to avoid unexpected breaking changes../mvnw clean verify after setup to ensure everything compiles and tests pass..env file (git-ignored) — never commit secrets to version control.spring.jpa.hibernate.ddl-auto=update setting is for development only — use Flyway or Liquibase in production.Weekly Installs
120
Repository
GitHub Stars
173
First Seen
Feb 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex104
gemini-cli104
github-copilot102
claude-code101
cursor99
amp99
Spring Boot 3.x OpenAPI 文档生成指南 - SpringDoc集成与Swagger UI配置
496 周安装
| Java Version | 21 | 17, 21 |
| Architecture | User choice | DDD or Layered |
| Docker Services | User choice | PostgreSQL, Redis, MongoDB (multi-select) |
| Build Tool | maven | maven, gradle |