Java Spring Boot Development Guidelines
A set of best practices and instructions for developing robust and secure applications using Java Spring Boot 3 with Maven, focusing on SOLID principles and OWASP best practices.
Technology Stack
- Framework: Java Spring Boot 3 with Maven
- Dependencies: Spring Web, Spring Data JPA, Thymeleaf, Lombok, PostgreSQL driver
- Java Version: Java 17
Application Logic Design
- Request and response handling in
RestController. - Database operations in
ServiceImplclasses viaRepositories. - Use DTOs for data transfer between layers.
Entities
- Annotate with
@Entity,@Data, and proper validation annotations. - Use
FetchType.LAZYfor relationships.
Repository (DAO)
- Annotate with
@Repository, extendJpaRepository. - Use JPQL for queries and
@EntityGraphfor relationships.
Service
- Implement logic in
ServiceImplclasses. - Use
@Transactionalfor multiple database operations.
Data Transfer Object (DTO)
- Use
recordtype unless specified otherwise. - Validate input parameters in the constructor.
RestController
- Annotate with
@RestController. - Use
@RequestMappingand HTTP method annotations. - Return
ResponseEntity<ApiResponse>.
ApiResponse Class
- Standardized response format with success/error status and message.
GlobalExceptionHandler Class
- Handles exceptions with standardized error responses.
Overview of .cursorrules prompt
This prompt outlines guidelines for developing robust and secure Java Spring Boot applications, emphasizing SOLID principles, OWASP best practices, and efficient layering of logic. It ensures that applications are maintainable, scalable, and secure by using Spring Data JPA for database operations and Thymeleaf for templating.
