anantbhandarkar/make-it-right/mir-backend-jvm-micronaut

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (Micronaut module). Micronaut 5.x / 4.x + Micronaut Data + Micronaut Security + Netty footguns. Covers: compile-time DI and AOT (bean definitions are generated at build, but resolution is still runtime, so NoSuchBeanException/NonUniqueBeanException surfaces after startup because singletons are lazy), bean scope pitfalls (@Singleton default), blocking the Netty event loop (@ExecuteOn(TaskExecutors.BLOCKING), virtual-thread backed where supported, or reactive types), Micronaut Data repository transaction scoping and self-invocation, compile-time AOP interceptor limits on final/private/new-ed instances, and Micronaut security (CORS wide open when enabled with no configurations, allowCredentials defaulting to true on 4.x and false on 5.x, @Secured object-level authorization, and the HTTP-client credential-leakage and unbounded-redirect advisories). Chains: mir-backend -> mir-backend-jvm -> this, which adds only Micronaut library mechanics. TRIGGER only when the JVM backend stack is Micronaut — building, reviewing, or debugging a Micronaut controller, service, repository, filter, HTTP client, or security rule. SKIP for Spring Boot (mir-backend-jvm-spring), Quarkus (mir-backend-jvm-quarkus), standalone Vert.x, Helidon, Ktor, every other non-Micronaut JVM framework, and every non-JVM runtime.

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-jvm-micronaut

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-jvm-micronaut.

/mir-backend-jvm-micronaut · Make It Right (Micronaut)

Bottom tier of the chain: mir-backend (generic gates) → mir-backend-jvm (JVM runtime model) → this (Micronaut library mechanics). Run the gates first; load the JVM runtime tier for threading, GC, and container-heap concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (virtual-thread pinning, pool sizing, GC tuning, `-XX:MaxRAMPercentage`, ThreadLocal hygiene, JMM visibility) live in `mir-backend-jvm` — not here.

Stack assumed: Micronaut 5.x (or 4.x — the differences are called out) · Micronaut Data JPA (Hibernate) or Micronaut Data JDBC · Micronaut Security · Micronaut HTTP Server (Netty) · GraalVM for native image.

Version status, verified 13 Aug 2026:

LineStatusWhat changes
Micronaut 5.xGA 20 May 2026 (5.0.0). Latest verified release 5.1.0, 27 Jul 2026Java 25 baseline — virtual threads, structured concurrency, scoped values and pattern matching are all available unconditionally. Groovy 5 and Kotlin 2.3 baselines, GraalVM 25.0.3. Adds a ScopedValue-based context-propagation implementation alongside the thread-local one
Micronaut 4.xStill maintained (4.10.x line)Keeps Java 17 and 21 support and runs on 25. Stay here if you cannot move to a Java 25 baseline

A Micronaut 5 answer written from Micronaut 4 memory will usually still compile; the risk is the opposite direction — 5-only APIs suggested for a 4.x project, and a Java 25 baseline assumed for a service still built on 17.

The Micronaut footguns AI walks into most

1. Compile-time DI — missing bean is a compile error, not a runtime NPE

Micronaut generates bean definitions and injection metadata at compile time via annotation processors — no runtime classpath scanning, no reflection for injection. What that does not buy you:

  • Candidate resolution still happens at runtime. A missing or ambiguous dependency raises NoSuchBeanException, NonUniqueBeanException, or DependencyInjectionException when the dependent bean is created — and because singletons are lazy, that can be well after startup rather than at build time. Do not tell a reviewer "if it compiled, the graph is wired." Force it with eager initialization or a context-startup test.
  • Classes used only via reflection (Jackson mixins, custom TypeConverter, serialization targets for native image) are not automatically discovered. Register them explicitly.
java
// WRONG — assumes runtime classpath scanning will find the bean
@Controller("/orders")
public class OrderController {
@Inject
OrderService service; // compile error if OrderService has no @Singleton/@Service
}
// RIGHT — ensure the injected type has a bean-defining annotation
@Singleton
public class OrderService { ... }
// Ambiguous bean: two @Singleton implementations of the same interface
// → compile error "Multiple bean definitions found for type..."
// FIX: qualify with @Named or @Primary
@Singleton
@Named("fast")
public class FastOrderService implements OrderService { ... }
@Inject @Named("fast") OrderService service;

`@Factory` for third-party types: if you need to inject a type you can't annotate, use @Factory:

java
@Factory
public class RedisFactory {
@Singleton
RedisClient redisClient(RedisConfig cfg) {
return RedisClient.create(cfg.getUri());
}
}
2. @Singleton default scope: never store per-request state

Micronaut beans are not implicitly singletons — a class needs a bean-defining annotation, and @Bean/@Prototype gives prototype scope. But almost every service you or an AI writes carries @Singleton, which is one lazily created instance shared by all threads. That is the same trap as Spring's singleton scope, and Micronaut's lack of a default @RequestScope proxy makes it easier to miss.

java
// WRONG — tenantId is a shared mutable field; threads stomp on each other
@Singleton
public class TenantContext {
private String tenantId; // shared across all concurrent requests
public void set(String t) { this.tenantId = t; }
public String get() { return tenantId; }
}
// RIGHT — pass tenant context as a method argument, or use a @RequestScope bean
// @RequestScope requires the HttpRequest to be in scope; use carefully
@RequestScope
public class TenantContext {
private String tenantId;
public void set(String t) { this.tenantId = t; }
public String get() { return tenantId; }
}
// Inject into singleton with @Inject Provider<TenantContext> ctx;
// so each invocation gets the request-scoped instance, not a singleton

Available scopes: @Singleton, @Prototype (new instance per injection point), @RequestScope (per HTTP request), @ThreadLocal (per thread — correct for pooled-thread use). Default to @Singleton for stateless services; use @Prototype for stateful helpers.

@ThreadLocal scope and thread-local context propagation both behave differently once every request has its own virtual thread — see mir-backend-jvm §2 and §7. Micronaut 5 offers a ScopedValue-based context-propagation implementation as an alternative to the thread-local one.

3. Blocking the Netty event loop: @ExecuteOn is mandatory for blocking work

Micronaut's HTTP server runs on Netty's event loop. Like Quarkus reactive, blocking the event loop thread degrades the entire server — one blocking call can stall all concurrent requests on that loop.

java
// WRONG — controller method runs on the event loop by default; JDBC blocks it
@Get("/report")
public Report getReport() {
return reportService.buildHeavyReport(); // blocking JDBC on event loop → server stall
}
// RIGHT — @ExecuteOn dispatches off the event loop
@Get("/report")
@ExecuteOn(TaskExecutors.BLOCKING) // current name; virtual threads when available
public Report getReport() {
return reportService.buildHeavyReport(); // event loop is free
}
// ALSO RIGHT — return a reactive type; Micronaut keeps the call non-blocking
@Get("/report")
public Mono<Report> getReport() {
return reportService.buildHeavyReportAsync(); // reactive, event loop not blocked
}

`TaskExecutors.BLOCKING` is the name to use. Micronaut detects virtual-thread support and backs the blocking executor with virtual threads when the JVM provides them, falling back to the platform-thread I/O pool otherwise. On Micronaut 5 (Java 25 baseline) that means virtual threads always. TaskExecutors.IO still exists and still names the pooled executor — code that hard-codes it opts out of virtual threads without saying so.

Two consequences of the virtual-thread path:

  • The pool no longer bounds concurrency. Size the datasource pool and any downstream limit explicitly; that is now the only ceiling. micronaut.executors.io.type=fixed with nThreads still applies to the platform-thread pool if you deliberately choose it.
  • @ExecuteOn is required on filters that block too (@ServerFilter / @RequestFilter methods), not just controllers. A blocking filter stalls the event loop exactly like a blocking controller.

For Kotlin coroutines: mark the controller function suspend; Micronaut handles the dispatch. Never call runBlocking on the event loop.

4. Micronaut Data transactions: @Transactional and repository scope

Micronaut Data uses compile-time-generated repositories (no runtime proxies). @Transactional is applied via a compile-time AOP interceptor — which means self-invocation bypasses the interceptor, same as Spring.

java
// WRONG — saveWithNotification calls notify() on this; interceptor not involved
@Singleton
public class OrderService {
@Transactional
public void saveWithNotification(Order o) {
repo.save(o);
notify(o); // direct call — @Transactional on notify() is not applied
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void notify(Order o) { ... } // never runs in its own tx
}
// RIGHT — extract to a separate @Singleton bean
@Singleton
public class NotificationService {
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void notify(Order o) { ... }
}

Micronaut Data repositories operate in the transaction of their caller. If you call a repository from outside a @Transactional boundary, each repository call gets its own auto-committed mini-transaction. This is correct for reads but breaks for multi-step writes.

JDBC repositories: Micronaut Data JDBC uses a simpler mapping layer than JPA — no lazy loading, no session, no LazyInitializationException. N+1 is still possible via explicit nested queries in a loop; use @Join on repository finder methods to specify eager joins.

5. Compile-time AOP interceptors: what they can and cannot intercept

Micronaut AOP is compile-time — the framework generates interceptor wrappers at build time. This is fast and native-image-friendly but has hard constraints:

  • Only beans managed by Micronaut's DI container can be intercepted. Objects created with new bypass AOP. @Transactional, @Cacheable, @Retryable all silently do nothing on a new-ed instance.
  • `final` methods cannot be intercepted (they can't be overridden in the generated subclass).
  • `private` methods cannot be intercepted for the same reason.
java
// WRONG — @Cacheable on a final method; compile-time warning, caching silently skipped
@Cacheable("products")
public final Product findProduct(Long id) { ... }
// RIGHT — remove final
@Cacheable("products")
public Product findProduct(Long id) { ... }
// WRONG — calling @Retryable from within the same class
public void upload(File f) {
sendToS3(f); // self-call; @Retryable not applied
}
@Retryable
public void sendToS3(File f) { ... }
// RIGHT — inject the bean and call through it, or restructure
@Inject S3Uploader uploader; // separate bean
public void upload(File f) { uploader.sendToS3(f); }
6. GraalVM native image with Micronaut: what Micronaut handles vs. what you must declare

Micronaut generates GraalVM metadata (reflect-config.json, resource-config.json, proxy-config.json) automatically for its own classes and for beans it discovers at compile time. The gaps:

  • Dynamic class loading or reflection outside Micronaut's DI — third-party libraries, JDBC drivers, Jackson polymorphic subtypes — must still be registered.
  • Resources not on the classpath path that are loaded with getClass().getResourceAsStream().
  • Runtime-initialized classes with side effects in static initializers (same trap as Quarkus — see runtime-map JVM notes).
java
// Annotate third-party reflection targets (@ReflectiveAccess in Micronaut 4 and 5)
@ReflectiveAccess
public class ThirdPartyDto { ... }
// Or use GraalVM reflect-config.json directly for classes you can't annotate
// src/main/resources/META-INF/native-image/reflect-config.json

Run native-image-agent with your test suite before your first native build to auto-generate the bulk of the config:

bash
java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image \
-jar app.jar

Then review and trim the generated config (it over-reports). Commit it alongside the source.

7. Micronaut Security: token validation and route-level authorization

Micronaut Security's @Secured or security rules in SecurityRule beans control access. The same IDOR trap applies as in Spring: role/authentication checks do not confirm object ownership.

java
// WRONG — checks role, not object ownership
@Get("/invoices/{id}")
@Secured("ROLE_USER")
public Invoice get(Long id) {
return invoiceRepo.findById(id).orElseThrow();
}

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-jvm-micronaut/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-jvm-micronaut)

Something wrong with this skill or its page? Tell us.