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.

referencessqs.md

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

SQS messaging

Use Spring Cloud AWS for SQS. It wraps the AWS SDK v2, gives you @SqsListener, and integrates with Boot autoconfiguration.

Dependencies

Add the BOM and starter to pom.xml. The BOM keeps Spring Cloud AWS modules version-aligned with each other.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.awspring.cloud</groupId>
      <artifactId>spring-cloud-aws-dependencies</artifactId>
      <version>3.2.1</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-aws-starter-sqs</artifactId>
  </dependency>
</dependencies>

io.awspring.cloud (AwsSpring, the community-led project) replaced the legacy Spring Cloud AWS group years ago. Don't add org.springframework.cloud:spring-cloud-starter-aws — that's the abandoned version.

Configuration

spring:
  cloud:
    aws:
      region:
        static: us-east-1
      credentials:
        # Production: omit. The default credentials chain (instance role,
        # env vars, ~/.aws/credentials) handles it. Override only for local dev.
        access-key: ${AWS_ACCESS_KEY_ID:}
        secret-key: ${AWS_SECRET_ACCESS_KEY:}
      sqs:
        endpoint: ${SQS_ENDPOINT:}   # set to http://localhost:4566 for LocalStack

app:
  queues:
    orders: orders-incoming

Producing messages

@Service
public class OrderEventPublisher {
    private final SqsTemplate sqsTemplate;
    private final String queueName;

    public OrderEventPublisher(SqsTemplate sqsTemplate,
                               @Value("${app.queues.orders}") String queueName) {
        this.sqsTemplate = sqsTemplate;
        this.queueName = queueName;
    }

    public void publish(OrderCreated event) {
        sqsTemplate.send(to -> to.queue(queueName).payload(event));
    }
}

SqsTemplate serializes the payload to JSON via the application's ObjectMapper. The event class can be a record.

Consuming messages

@Component
public class OrderEventListener {
    private static final Logger log = LoggerFactory.getLogger(OrderEventListener.class);
    private final OrderProjection projection;

    public OrderEventListener(OrderProjection projection) {
        this.projection = projection;
    }

    @SqsListener("${app.queues.orders}")
    public void onOrderCreated(OrderCreated event) {
        log.info("processing order {}", event.orderId());
        projection.apply(event);
    }
}

Key behavior:

  • The container polls SQS continuously and dispatches to the method.
  • If the method returns normally, the message is acknowledged (deleted from the queue).
  • If it throws, the message is not deleted — SQS will redeliver after the visibility timeout. After maxReceiveCount deliveries, AWS sends it to the DLQ if one is configured on the queue.

Configure the DLQ on the queue itself in AWS, not in code. maxReceiveCount belongs in the queue's redrive policy.

Idempotency

Always assume at-least-once delivery. The same message may arrive twice. Make handlers idempotent:

  • Use the event's natural ID (e.g. orderId) as a dedupe key.
  • Check "already processed?" before applying side effects.
  • For outbound calls, prefer idempotent operations or pass an idempotency key.

Error handling

For known transient failures (timeouts, 503s), re-throw — let SQS redeliver. For poison messages (malformed, business-invalid) the redrive-to-DLQ behavior is what you want; don't silently swallow them.

To customize the container (concurrency, batch size, visibility), define a SqsMessageListenerContainerFactory bean. Default factory is fine for most use cases.

Local dev: LocalStack

Run LocalStack via Docker, point spring.cloud.aws.sqs.endpoint at it, and create the queue at startup:

docker run --rm -p 4566:4566 localstack/localstack
aws --endpoint-url http://localhost:4566 sqs create-queue --queue-name orders-incoming

For tests, prefer Testcontainers' LocalStackContainer — see testing.md.

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