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 从公开仓库中收录这些内容。

举报或申请下架