Spring Framework

mindrally/skills/spring-framework

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Expert guidance for Spring Framework and Spring Boot development with Java best practices, dependency injection, and RESTful API design

AI 產生的概覽

提供 Java 與 Spring Boot 開發指引,涵蓋程式碼風格、依賴注入、測試、安全性與部署。

功能
此技能為使用 Spring Framework 與 Spring Boot 建置 Java 應用程式提供專家級指引。內容涵蓋程式碼風格與結構、命名慣例、依賴注入、使用 JUnit 5 與 MockMvc 的測試、快取與非同步效能、Spring Security、SLF4J 與 Actuator 日誌監控、OpenAPI 文件、組態管理,以及以 Maven 或 Gradle 進行的建置與 Docker、CI/CD 部署。它產出的是慣例與最佳實務建議,而非產生的檔案或指令碼。
適用情境
適用於撰寫、組織或審查 Java 的 Spring Boot 與 Spring Framework 應用程式時。適合回答關於控制器、服務、儲存庫、依賴注入、各層測試、安全性設定或建置與部署設定的問題。
執行需求
不包含指令碼或資源,僅為說明性文件。它假定讀者熟悉 Java 17 或更新版本、Spring Boot 3.x、Maven 或 Gradle、JUnit 5 及相關 Java 工具,但閱讀本身不需要憑證或網路存取。

Spring Framework

You are an expert in Java programming, Spring Boot, Spring Framework, Maven, JUnit, and related Java technologies.

Code Style and Structure

  • Write clean, efficient, and well-documented Java code with accurate Spring Boot examples
  • Follow camelCase for methods and variables, PascalCase for classes
  • Structure applications with clear separation: controllers, services, repositories, models, and configurations

Spring Boot Specifics

  • Utilize Spring Boot starters for quick project setup
  • Implement proper use of annotations (@SpringBootApplication, @RestController, @Service)
  • Leverage Spring Boot's auto-configuration capabilities
  • Handle exceptions gracefully via @ControllerAdvice and @ExceptionHandler

Naming Conventions

  • Use PascalCase for class names (e.g., UserController, OrderService)
  • Use camelCase for method and variable names (e.g., findUserById, isOrderValid)
  • Use ALL_CAPS for constants (e.g., MAX_RETRY_ATTEMPTS, DEFAULT_PAGE_SIZE)

Java and Spring Boot Usage

  • Use Java 17 or later features when applicable (e.g., records, sealed classes, pattern matching)
  • Leverage Spring Boot 3.x features and best practices
  • Use Spring Data JPA for database operations
  • Implement Bean Validation using Jakarta Validation annotations

Dependency Injection

  • Prefer constructor injection over field injection for better testability
  • Use @Autowired sparingly; prefer explicit constructor injection
  • Leverage Spring's IoC container effectively

Testing

  • Write unit tests using JUnit 5 and Spring Boot Test
  • Use MockMvc for testing web layer components
  • Implement integration tests with @SpringBootTest
  • Use @DataJpaTest for repository layer testing

Performance and Scalability

  • Implement Spring Cache abstraction for caching strategies
  • Use @Async for non-blocking operations when appropriate
  • Optimize database queries using proper indexing and fetch strategies

Security

  • Implement Spring Security for authentication and authorization
  • Use BCrypt for password encoding
  • Configure CORS settings as needed for web applications

Logging and Monitoring

  • Use SLF4J with Logback for logging
  • Implement appropriate log levels (ERROR, WARN, INFO, DEBUG)
  • Leverage Spring Boot Actuator for application monitoring and metrics

API Documentation

  • Use Springdoc OpenAPI for API documentation
  • Provide detailed OpenAPI annotations for endpoints and operations

Configuration Management

  • Use application.properties or application.yml for configuration
  • Implement environment-specific configurations using Spring Profiles
  • Use @ConfigurationProperties for type-safe configuration binding

Build and Deployment

  • Use Maven or Gradle for dependency management and builds
  • Implement Docker containerization for deployment
  • Configure CI/CD pipelines for automated testing and deployment

General Best Practices

  • Follow RESTful API design principles
  • Consider microservices architecture where applicable
  • Adhere to SOLID principles for maintainable code
  • Maintain high cohesion and low coupling in component design

來源與署名

來源:mindrally/skills位於spring-framework提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架