Spring Boot Engineer

作者 jeffallan1be15d8064f8MIT11K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 天前更新

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.

AI 產生的概覽

指導 Spring Boot 3.x 後端實作:REST 控制器、JPA 資料存取、Security 6、WebFlux 與測試。

功能
提供建構 Spring Boot 3.x 應用程式的工作流程與參考指引,包含分層服務、儲存庫與 REST 控制器程式碼範例、DTO、例外處理與測試切片。它透過五份參考文件涵蓋 Spring Data JPA、Spring Security 6 驗證、響應式 WebFlux 端點以及 Spring Cloud 整合。同時列出必須遵守與禁止使用的模式,例如建構子注入、輸入驗證與外部化密鑰。
適用情境
適用於實作或審查 Spring Boot 3.x 服務、微服務或響應式 Java 應用程式的情境。適合涉及 Spring Data JPA、Spring Security 6、WebFlux、Spring Cloud 或 Java REST API 設計的工作。
執行需求
僅為指令與參考文件,不附帶指令碼。所述工作假定已有 Java 專案、Spring Boot 3.x 以及用於執行測試的 Maven 或 Gradle wrapper。

Spring Boot Engineer

Core Workflow

  1. Analyze requirements — Identify service boundaries, APIs, data models, security needs
  2. Design architecture — Plan microservices, data access, cloud integration, security; confirm design before coding
  3. Implement — Create services with constructor injection and layered architecture (see Quick Start below)
  4. 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
  5. 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
  6. 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:

TopicReferenceLoad When
Web Layerreferences/web.mdControllers, REST APIs, validation, exception handling
Data Accessreferences/data.mdSpring Data JPA, repositories, transactions, projections
Securityreferences/security.mdSpring Security 6, OAuth2, JWT, method security
Cloud Nativereferences/cloud.mdSpring Cloud, Config, Discovery, Gateway, resilience
Testingreferences/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

java
@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

java
public interface ProductRepository extends JpaRepository<Product, Long> {    List<Product> findByNameContainingIgnoreCase(String name);}

Service (constructor injection)

java
@Servicepublic 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

java
@RestController@RequestMapping("/api/v1/products")@Validatedpublic 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)

java
public record ProductRequest(    @NotBlank String name,    @DecimalMin("0.0") BigDecimal price) {}

Global Exception Handler

java
@RestControllerAdvicepublic 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

java
@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

RuleCorrect Pattern
Constructor injectionpublic 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 internalsCatch domain exceptions in @RestControllerAdvice; return problem details, not stack traces
Externalize secretsUse 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)

Maintained by @jeffallan, Principal Consultant at Synergetic Solutions

Documentation

來源與署名

來源:jeffallan/claude-skills位於skills/spring-boot-engineer提交1be15d8

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架