Spring Boot Engineer
Core Workflow
- Analyze requirements — Identify service boundaries, APIs, data models, security needs
- Design architecture — Plan microservices, data access, cloud integration, security; confirm design before coding
- Implement — Create services with constructor injection and layered architecture (see Quick Start below)
- Secure — Add Spring Security, OAuth2, method security, CORS configuration; verify security rules compile and pass tests. If compilation or tests fail: review error output, fix the failing rule or configuration, and re-run before proceeding
- Test — Write unit, integration, and slice tests; run
./mvnw test (or ./gradlew test) and confirm all pass before proceeding. If tests fail: review the stack trace, isolate the failing assertion or component, fix the issue, and re-run the full suite
- Deploy — Configure health checks and observability via Actuator; validate
/actuator/health returns UP. If health is DOWN: check the components detail in the response, resolve the failing component (e.g., datasource, broker), and re-validate
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Web Layer |
references/web.md |
Controllers, REST APIs, validation, exception handling |
| Data Access |
references/data.md |
Spring Data JPA, repositories, transactions, projections |
| Security |
references/security.md |
Spring Security 6, OAuth2, JWT, method security |
| Cloud Native |
references/cloud.md |
Spring Cloud, Config, Discovery, Gateway, resilience |
| Testing |
references/testing.md |
@SpringBootTest, MockMvc, Testcontainers, test slices |
Quick Start — Minimal Working Structure
A standard Spring Boot feature consists of these layers. Use these as copy-paste starting points.
Entity
@Entity
@Table(name = "products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
private String name;
@DecimalMin("0.0")
private BigDecimal price;
// getters / setters or use @Data (Lombok)
}
Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
List<Product> findByNameContainingIgnoreCase(String name);
}
Service (constructor injection)
@Service
public class ProductService {
private final ProductRepository repo;
public ProductService(ProductRepository repo) { // constructor injection — no @Autowired
this.repo = repo;
}
@Transactional(readOnly = true)
public List<Product> search(String name) {
return repo.findByNameContainingIgnoreCase(name);
}
@Transactional
public Product create(ProductRequest request) {
var product = new Product();
product.setName(request.name());
product.setPrice(request.price());
return repo.save(product);
}
}
REST Controller
@RestController
@RequestMapping("/api/v1/products")
@Validated
public class ProductController {
private final ProductService service;
public ProductController(ProductService service) {
this.service = service;
}
@GetMapping
public List<Product> search(@RequestParam(defaultValue = "") String name) {
return service.search(name);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Product create(@Valid @RequestBody ProductRequest request) {
return service.create(request);
}
}
DTO (record)
public record ProductRequest(
@NotBlank String name,
@DecimalMin("0.0") BigDecimal price
) {}
Global Exception Handler
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, String> handleValidation(MethodArgumentNotValidException ex) {
return ex.getBindingResult().getFieldErrors().stream()
.collect(Collectors.toMap(FieldError::getField, FieldError::getDefaultMessage));
}
@ExceptionHandler(EntityNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Map<String, String> handleNotFound(EntityNotFoundException ex) {
return Map.of("error", ex.getMessage());
}
}
Test Slice
@WebMvcTest(ProductController.class)
class ProductControllerTest {
@Autowired MockMvc mockMvc;
@MockBean ProductService service;
@Test
void createProduct_validRequest_returns201() throws Exception {
var product = new Product(); product.setName("Widget"); product.setPrice(BigDecimal.TEN);
when(service.create(any())).thenReturn(product);
mockMvc.perform(post("/api/v1/products")
.contentType(MediaType.APPLICATION_JSON)
.content("""{"name":"Widget","price":10.0}"""))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.name").value("Widget"));
}
}
Constraints
MUST DO
| Rule |
Correct Pattern |
| Constructor injection |
public MyService(Dep dep) { this.dep = dep; } |
| Validate API input |
@Valid @RequestBody MyRequest req on every mutating endpoint |
| Type-safe config |
@ConfigurationProperties(prefix = "app") bound to a record/class |
| Appropriate stereotype |
@Service for business logic, @Repository for data, @RestController for HTTP |
| Transaction scope |
@Transactional on multi-step writes; @Transactional(readOnly = true) on reads |
| Hide internals |
Catch domain exceptions in @RestControllerAdvice; return problem details, not stack traces |
| Externalize secrets |
Use environment variables or Spring Cloud Config — never application.properties |
MUST NOT DO
- Use field injection (
@Autowired on fields)
- Skip input validation on API endpoints
- Use
@Component when @Service/@Repository/@Controller applies
- Mix blocking and reactive code (e.g., calling
.block() inside a WebFlux chain)
- Store secrets or credentials in
application.properties/application.yml
- Hardcode URLs, credentials, or environment-specific values
- Use deprecated Spring Boot 2.x patterns (e.g.,
WebSecurityConfigurerAdapter)
1---
2name: spring-boot-engineer
3description: Generates Spring Boot 3.x configurations, creates REST controllers, implements Spring Security 6 authentication flows, sets up Spring Data JPA repositories, and configures reactive WebFlux endpoints. Use when building Spring Boot 3.x applications, microservices, or reactive Java applications; invoke for Spring Data JPA, Spring Security 6, WebFlux, Spring Cloud integration, Java REST API design, or Microservices Java architecture.
4license: MIT
5metadata:
6 source: https://skillmd.com/skills/aibot88/spring-boot-engineer
7 author: https://github.com/Jeffallan
8 version: "1.1.0"
9 domain: backend
10 triggers: Spring Boot, Spring Framework, Spring Cloud, Spring Security, Spring Data JPA, Spring WebFlux, Microservices Java, Java REST API, Reactive Java
11 role: specialist
12 scope: implementation
13 output-format: code
14 related-skills: java-architect, database-optimizer, microservices-architect, devops-engineer
15---
16
17# Spring Boot Engineer
18
19## Core Workflow
20
211. **Analyze requirements** — Identify service boundaries, APIs, data models, security needs
222. **Design architecture** — Plan microservices, data access, cloud integration, security; confirm design before coding
233. **Implement** — Create services with constructor injection and layered architecture (see Quick Start below)
244. **Secure** — Add Spring Security, OAuth2, method security, CORS configuration; verify security rules compile and pass tests. If compilation or tests fail: review error output, fix the failing rule or configuration, and re-run before proceeding
255. **Test** — Write unit, integration, and slice tests; run `./mvnw test` (or `./gradlew test`) and confirm all pass before proceeding. If tests fail: review the stack trace, isolate the failing assertion or component, fix the issue, and re-run the full suite
266. **Deploy** — Configure health checks and observability via Actuator; validate `/actuator/health` returns `UP`. If health is `DOWN`: check the `components` detail in the response, resolve the failing component (e.g., datasource, broker), and re-validate
27
28## Reference Guide
29
30Load detailed guidance based on context:
31
32| Topic | Reference | Load When |
33|-------|-----------|-----------|
34| Web Layer | `references/web.md` | Controllers, REST APIs, validation, exception handling |
35| Data Access | `references/data.md` | Spring Data JPA, repositories, transactions, projections |
36| Security | `references/security.md` | Spring Security 6, OAuth2, JWT, method security |
37| Cloud Native | `references/cloud.md` | Spring Cloud, Config, Discovery, Gateway, resilience |
38| Testing | `references/testing.md` | @SpringBootTest, MockMvc, Testcontainers, test slices |
39
40## Quick Start — Minimal Working Structure
41
42A standard Spring Boot feature consists of these layers. Use these as copy-paste starting points.
43
44### Entity
45
46```java
47@Entity
48@Table(name = "products")
49public class Product {
50 @Id
51 @GeneratedValue(strategy = GenerationType.IDENTITY)
52 private Long id;
53
54 @NotBlank
55 private String name;
56
57 @DecimalMin("0.0")
58 private BigDecimal price;
59
60 // getters / setters or use @Data (Lombok)
61}
62```
63
64### Repository
65
66```java
67public interface ProductRepository extends JpaRepository<Product, Long> {
68 List<Product> findByNameContainingIgnoreCase(String name);
69}
70```
71
72### Service (constructor injection)
73
74```java
75@Service
76public class ProductService {
77 private final ProductRepository repo;
78
79 public ProductService(ProductRepository repo) { // constructor injection — no @Autowired
80 this.repo = repo;
81 }
82
83 @Transactional(readOnly = true)
84 public List<Product> search(String name) {
85 return repo.findByNameContainingIgnoreCase(name);
86 }
87
88 @Transactional
89 public Product create(ProductRequest request) {
90 var product = new Product();
91 product.setName(request.name());
92 product.setPrice(request.price());
93 return repo.save(product);
94 }
95}
96```
97
98### REST Controller
99
100```java
101@RestController
102@RequestMapping("/api/v1/products")
103@Validated
104public class ProductController {
105 private final ProductService service;
106
107 public ProductController(ProductService service) {
108 this.service = service;
109 }
110
111 @GetMapping
112 public List<Product> search(@RequestParam(defaultValue = "") String name) {
113 return service.search(name);
114 }
115
116 @PostMapping
117 @ResponseStatus(HttpStatus.CREATED)
118 public Product create(@Valid @RequestBody ProductRequest request) {
119 return service.create(request);
120 }
121}
122```
123
124### DTO (record)
125
126```java
127public record ProductRequest(
128 @NotBlank String name,
129 @DecimalMin("0.0") BigDecimal price
130) {}
131```
132
133### Global Exception Handler
134
135```java
136@RestControllerAdvice
137public class GlobalExceptionHandler {
138 @ExceptionHandler(MethodArgumentNotValidException.class)
139 @ResponseStatus(HttpStatus.BAD_REQUEST)
140 public Map<String, String> handleValidation(MethodArgumentNotValidException ex) {
141 return ex.getBindingResult().getFieldErrors().stream()
142 .collect(Collectors.toMap(FieldError::getField, FieldError::getDefaultMessage));
143 }
144
145 @ExceptionHandler(EntityNotFoundException.class)
146 @ResponseStatus(HttpStatus.NOT_FOUND)
147 public Map<String, String> handleNotFound(EntityNotFoundException ex) {
148 return Map.of("error", ex.getMessage());
149 }
150}
151```
152
153### Test Slice
154
155```java
156@WebMvcTest(ProductController.class)
157class ProductControllerTest {
158 @Autowired MockMvc mockMvc;
159 @MockBean ProductService service;
160
161 @Test
162 void createProduct_validRequest_returns201() throws Exception {
163 var product = new Product(); product.setName("Widget"); product.setPrice(BigDecimal.TEN);
164 when(service.create(any())).thenReturn(product);
165
166 mockMvc.perform(post("/api/v1/products")
167 .contentType(MediaType.APPLICATION_JSON)
168 .content("""{"name":"Widget","price":10.0}"""))
169 .andExpect(status().isCreated())
170 .andExpect(jsonPath("$.name").value("Widget"));
171 }
172}
173```
174
175## Constraints
176
177### MUST DO
178
179| Rule | Correct Pattern |
180|------|----------------|
181| Constructor injection | `public MyService(Dep dep) { this.dep = dep; }` |
182| Validate API input | `@Valid @RequestBody MyRequest req` on every mutating endpoint |
183| Type-safe config | `@ConfigurationProperties(prefix = "app")` bound to a record/class |
184| Appropriate stereotype | `@Service` for business logic, `@Repository` for data, `@RestController` for HTTP |
185| Transaction scope | `@Transactional` on multi-step writes; `@Transactional(readOnly = true)` on reads |
186| Hide internals | Catch domain exceptions in `@RestControllerAdvice`; return problem details, not stack traces |
187| Externalize secrets | Use environment variables or Spring Cloud Config — never `application.properties` |
188
189### MUST NOT DO
190- Use field injection (`@Autowired` on fields)
191- Skip input validation on API endpoints
192- Use `@Component` when `@Service`/`@Repository`/`@Controller` applies
193- Mix blocking and reactive code (e.g., calling `.block()` inside a WebFlux chain)
194- Store secrets or credentials in `application.properties`/`application.yml`
195- Hardcode URLs, credentials, or environment-specific values
196- Use deprecated Spring Boot 2.x patterns (e.g., `WebSecurityConfigurerAdapter`)