Index of every page on this site: llms.txt
All skills
roby2358 avatar

/java-spring-boot-coldstart

@956ee23
by roby2358roby2358/skills5 stars
Run it yourself

Bootstrap and build Java 21 Spring Boot 3 services for a team with mixed Java experience. Covers REST APIs, SQS messaging via Spring Cloud AWS, Spring Security 6 (JWT resource server), and JUnit 5 + Mockito testing. Maven, no Lombok. Use when creating a new Spring Boot project, adding REST endpoints/SQS listeners/security config, or writing tests against Spring components.

Use this Skill: https://skilld.dev/gh/roby2358/skills/java-spring-boot-coldstart

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesrest.md

≈844 tokens on demand. Your agent reads this file only when SKILL.md points to it.

REST APIs

Controller

A controller is a thin adapter: parse the request, call a service, return a DTO. Keep business logic in services.

@RestController
@RequestMapping("/orders")
public class OrderController {
    private final OrderService service;

    public OrderController(OrderService service) {
        this.service = service;
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public OrderResponse create(@Valid @RequestBody CreateOrderRequest request) {
        return service.create(request);
    }

    @GetMapping("/{id}")
    public OrderResponse get(@PathVariable String id) {
        return service.findById(id);
    }
}

Notes:

  • @Valid triggers Bean Validation on the body. Without it, the constraints on the record are ignored.
  • Return DTOs (records), never JPA entities. Entities leak persistence concerns and risk lazy-loading explosions during serialization.
  • @ResponseStatus(HttpStatus.CREATED) keeps status code declaration next to the handler. For dynamic status, return ResponseEntity<...> instead.

Validation

Annotate request records with jakarta.validation.constraints.*:

public record CreateOrderRequest(
    @NotBlank @Size(max = 64) String customerId,
    @NotEmpty @Valid List<LineItem> items,
    @Email String notifyEmail
) {
    public record LineItem(
        @NotBlank String sku,
        @Min(1) int quantity
    ) {}
}

Use @Valid on the nested list element type so each item is also validated. @NotEmpty on the list rejects []; @NotNull only rejects null.

Error handling

Spring Boot 3 renders errors as RFC 7807 ProblemDetail JSON when you opt in:

spring:
  mvc:
    problemdetails:
      enabled: true

Throw domain exceptions; translate them to HTTP in one place with @RestControllerAdvice:

@RestControllerAdvice
public class ApiExceptionHandler {

    @ExceptionHandler(OrderNotFoundException.class)
    public ProblemDetail handleNotFound(OrderNotFoundException ex) {
        return ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, ex.getMessage());
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ProblemDetail handleValidation(MethodArgumentNotValidException ex) {
        ProblemDetail pd = ProblemDetail.forStatusAndDetail(
            HttpStatus.BAD_REQUEST, "Validation failed");
        pd.setProperty("errors", ex.getBindingResult().getFieldErrors().stream()
            .map(fe -> Map.of("field", fe.getField(), "message", fe.getDefaultMessage()))
            .toList());
        return pd;
    }
}

Domain exceptions stay framework-agnostic — they don't know about HTTP. The advice owns the translation. Don't catch exceptions in controllers just to convert them.

Pagination

Accept Pageable directly; Spring binds ?page=0&size=20&sort=createdAt,desc automatically.

@GetMapping
public Page<OrderResponse> list(Pageable pageable) {
    return service.list(pageable);
}

Common pitfalls

  • Returning entities — couples API to schema. Always map to a DTO.
  • @RequestBody without @Valid — validation silently does nothing.
  • Throwing RuntimeException for "not found" — produces a 500. Define a real exception and map it to 404.
  • Catching exceptions in controllers — defeats @RestControllerAdvice. Let them propagate.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6mo3 checks · Risk SAFE
  • Gen Agent Trust Hub6mo

    This skill provides a set of templates and instructions for bootstrapping and developing Java Spring Boot 3 applications. It uses official and well-known resources, follow industry best practices for security and configuration, and contains no malicious patterns.

  • Socket6mo

    No alerts

  • Snyk6mo

    Risk: LOW · No issues

Signed by skilld at 956ee23. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 7 months ago

README badge

README badge for roby2358/skills/java-spring-boot-coldstart