Spring Boot Microservices Coding Style Guidelines and Best Practices

Wenqi Glantz
CodeX
Published in
22 min readSep 7, 2021

--

Photo by Wenqi at Worlds End State Park

Through working with Spring Boot microservices over the years, I have compiled a list of coding style guidelines and best practices. This list is not comprehensive at all, but I hope you may find a point or two as takeaway, whether you are a new or seasoned Spring Boot microservices developer.

· 1. Modular Project Structure
· 2. Project Dependency Standards
· 3. Logging Rules
· 4. Configure JSON Logging with Logback
· 5. Auto-configuration
· 6. Keep Controllers Simple and Clean
· 7. Focus Services on Business Logic
· 8. Favor Constructor Injection Instead of @Autowired
· 9. Global Exception Handling
· 10. Open API Specification Code Documentation
· 11. Optimize Swagger UI Look and Feel
· 12. Pagination and Sorting with Spring Data JPA
· 13. Bean Validations
· 14. External Config Inject at Runtime
· 15. Expose Health Check Endpoints
· 16. Extra Dependencies Overhead
· 17. Automate Dependency Upgrade
· 18. Use Lombok
· 19. Apply Checkstyle
· 20. Dapr for Event Driven Programming
· 21. Schema-Per-Service Database Design
· 22. Liquibase for Database Schema Change Management
· 23. Resilience4j for Circuit Breaker
· 24. Backend for Frontend (BFF) as API Gateway
· 25. Pact for Consumer Driven Contract Testing
· 26. JUnit 5 for Unit Test
· 27. Cucumber for Behavior Driven Development (BDD)
· 28. JaCoCo for Test Coverage
· 29. Automate

--

--