A specialized skill for building production-grade Java Spring Boot backend services.
Activate this skill when user intent involves:
spring-boot-starter-parent as parent POM| Scenario | Starter |
|---|---|
| ---------- | --------- |
| Web/REST API | spring-boot-starter-web |
| Database (JPA) | spring-boot-starter-data-jpa |
| Database (MyBatis) | mybatis-spring-boot-starter |
| Validation | spring-boot-starter-validation |
| Security | spring-boot-starter-security |
| Redis | spring-boot-starter-data-redis |
| RabbitMQ/Kafka | spring-boot-starter-amqp / spring-kafka |
| Scheduled Tasks | spring-boot-starter-quartz |
| Actuator | spring-boot-starter-actuator |
| Test | spring-boot-starter-test |
| Lombok | lombok (scope: provided) |
| MapStruct | mapstruct (scope: provided) |
| Swagger/OpenAPI | springdoc-openapi-starter-webmvc-ui |
Follow a layered architecture with clear separation of concerns:
src/main/java/com/example/project/
├── controller/ # REST endpoints, request/response DTOs
├── service/ # Business logic interfaces
│ └── impl/ # Service implementations
├── mapper/ # Data access layer (MyBatis) or repository/ (JPA)
├── entity/ # Database entity classes
├── dto/ # Data Transfer Objects
│ ├── request/ # Incoming request DTOs
│ └── response/ # Outgoing response DTOs
├── config/ # Configuration classes
├── common/ # Shared utilities, constants, enums
│ ├── exception/ # Custom exceptions & global handler
│ ├── result/ # Unified API response wrapper
│ └── util/ # Utility classes
└── Application.java
@Service.XxxControllerXxxServiceXxxServiceImplXxxMapperXxx (singular noun, matches table name in snake_case)XxxRequest, XxxResponse, XxxDTO@Valid for request body validation```json
{ "code": 200, "message": "success", "data": { ... } }
```
@RestControllerAdvice + @ExceptionHandler for global error handlingPageable (Spring Data) or custom pagination DTORuntimeException@Slf4jserver:
port: 8080
spring:
profiles:
active: dev
datasource:
url: jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
maximum-pool-size: 20
minimum-idle: 5
jpa:
hibernate:
ddl-auto: validate
show-sql: false
open-in-view: false
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
logging:
level:
com.example.project: info
application-dev.yml — Local development (H2 or local MySQL)application-test.yml — Test environmentapplication-prod.yml — Production (externalized config, no hardcoded secrets)@WebMvcTest or MockMvc@DataJpaTest with H2 in-memory DBmethodName_stateUnderTest_expectedBehavior (e.g., createUser_withValidInput_returnsCreatedUser)@Lazy or restructure@Transactional is on public methods@EntityGraph or JOIN FETCH in JPA; use in MyBatisspring.jpa.open-in-view and eagerly fetch needed dataserverTimezone=Asia/Shanghai in JDBC URL; use Instant/LocalDateTime over DateDetailed reference documents are available in the references/ directory:
references/spring-boot-common-patterns.md — Common code patterns and recipesreferences/troubleshooting.md — Frequently encountered errors and solutionsLoad these files when relevant to the current task (e.g., when debugging or implementing a specific pattern).
共 1 个版本