| name | spring-boot-engineer |
| description | Use when implementing Spring Boot 3.x applications. Provides hands-on implementation patterns for web, data, security, testing, and cloud-native development. |
Spring Boot Engineer - Implementation Guide
Spring Boot 3.x Implementation Patterns
This skill provides concrete implementation references for building production-ready Spring Boot applications.
Quick Start Checklist
- Initialize project with Spring Initializr or Maven archetype
- Configure
application.yml with profiles
- Set up database with Flyway migrations
- Implement domain model (entities, DTOs, mappers)
- Build REST API layer (controllers, validation, exception handling)
- Add security (authentication, authorization)
- Write tests (unit, integration, API)
- Configure CI/CD pipeline
- Create Docker Compose for local development
Key Conventions
- Package structure:
pl.piomin.services.<module>.[layer]
- Prefer Records: Use Java records for DTOs and value objects. Lombok is allowed but records are preferred
- Constructor injection: Always use constructor injection, no
@Autowired
- Validation: Use Bean Validation annotations on request DTOs
- Transactions:
@Transactional on service methods, readOnly = true for queries
Reference Documents
| Topic | Reference File | Description |
|---|
| Web Layer | references/web.md | REST controllers, validation, exception handling, CORS |
| Data Layer | references/data.md | JPA entities, repositories, specifications, transactions |
| Security | references/security.md | Spring Security 6, JWT, OAuth2, method security |
| Testing | references/testing.md | Unit, integration, and slice tests, Testcontainers |
| Cloud Native | references/cloud.md | Spring Cloud, Gateway, Resilience4j, K8s deployment |
Common Patterns Summary
Service with Full Error Handling
@Service
public class CustomerService {
private static final Logger log = LoggerFactory.getLogger(CustomerService.class);
private final CustomerRepository customerRepository;
private final CustomerMapper customerMapper;
private final ApplicationEventPublisher eventPublisher;
public CustomerService(CustomerRepository customerRepository,
CustomerMapper customerMapper,
ApplicationEventPublisher eventPublisher) {
this.customerRepository = customerRepository;
this.customerMapper = customerMapper;
this.eventPublisher = eventPublisher;
}
@Transactional(readOnly = true)
public CustomerResponse findById(Long id) {
return customerRepository.findById(id)
.map(customerMapper::toResponse)
.orElseThrow(() -> new ResourceNotFoundException("Customer", id));
}
@Transactional
public CustomerResponse create(CustomerRequest request) {
if (customerRepository.existsByEmail(request.email())) {
throw new DuplicateResourceException("Customer", "email", request.email());
}
Customer customer = customerMapper.toEntity(request);
Customer saved = customerRepository.save(customer);
eventPublisher.publishEvent(new CustomerCreatedEvent(saved.getId(), saved.getEmail()));
log.info("Customer created: id={}", saved.getId());
return customerMapper.toResponse(saved);
}
}
Complete Application Configuration
spring:
application:
name: my-service
profiles:
active: ${SPRING_PROFILES_ACTIVE:dev}
datasource:
url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:mydb}
username: ${DB_USERNAME:postgres}
password: ${DB_PASSWORD:postgres}
hikari:
maximum-pool-size: 10
minimum-idle: 5
connection-timeout: 30000
jpa:
hibernate:
ddl-auto: validate
open-in-view: false
flyway:
enabled: true
locations: classpath:db/migration
server:
port: ${SERVER_PORT:8080}
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus