Prev Next

Java / Micronaut Interview questions

1. What is Micronaut? 2. What are the key features of Micronaut? 3. What is dependency injection in Micronaut? 4. What are Micronaut beans? 5. What is the purpose of the @Singleton annotation in Micronaut? 6. What are the types of bean scopes in Micronaut? 7. How do you create a Micronaut application? 8. What is Micronaut Launch? 9. What is ahead-of-time (AOT) compilation in Micronaut? 10. What are Micronaut controllers? 11. How do you define a REST endpoint in Micronaut? 12. What is the purpose of the @Inject annotation in Micronaut? 13. What are Micronaut configuration properties? 14. Describe how application.yml is used in Micronaut? 15. What is the Micronaut HTTP Client? 16. Why is Micronaut faster at startup than traditional Spring Boot applications? 17. Why does Micronaut avoid using reflection? 18. How does Micronaut achieve compile-time dependency injection? 19. What is the difference between Micronaut and Spring Boot? 20. What is the difference between @Singleton and @Prototype scope in Micronaut? 21. When should you use @Factory in Micronaut? 22. How does Micronaut Data work? 23. What is the difference between Micronaut Data JDBC and Micronaut Data JPA? 24. How do you implement bean validation in Micronaut? 25. How does Micronaut implement AOP (aspect-oriented programming)? 26. How does Micronaut support reactive programming? 27. What is the difference between a Micronaut declarative HTTP client and the low-level HttpClient? 28. How do you implement client-side load balancing in Micronaut? 29. What is Micronaut's service discovery mechanism? 30. How do you implement retries and circuit breakers in Micronaut? 31. What is the difference between @Client and @Controller in Micronaut? 32. How do you handle exceptions globally in a Micronaut application? 33. What is the purpose of Micronaut's BeanContext and ApplicationContext? 34. How does Micronaut support GraalVM native image compilation? 35. When would you choose Micronaut over Spring Boot for a new project? 36. Explain the internal working of Micronaut's compile-time dependency injection? 37. Explain the lifecycle of a Micronaut bean? 38. Explain the execution flow of an HTTP request in Micronaut? 39. How can you optimize Micronaut application startup time further? 40. How do you troubleshoot slow or failing GraalVM native image builds in Micronaut? 41. What is the difference between Micronaut's bean introspection and Java reflection? 42. Explain the internal working of Micronaut's AOP proxy generation? 43. Explain the internal working of Micronaut Data repository method generation? 44. How do you implement distributed tracing across Micronaut microservices? 45. How do you secure a Micronaut application with JWT authentication? 46. How does Micronaut resolve configuration properties across multiple environments? 47. Explain the internal working of Micronaut's event publishing system? 48. How do you troubleshoot excessive memory usage in a Micronaut native image at runtime? 49. How do you troubleshoot a Micronaut bean that fails to inject due to ambiguous qualifiers? 50. Explain how Micronaut's compile-time architecture influences microservice design decisions in real projects?

1. What is Micronaut?

Micronaut is a modern, JVM-based framework for building modular, testable microservice and serverless applications in Java, Kotlin, or Groovy. It was created by the team behind Grails and is now maintained by the Micronaut Foundation, with the current major line...

Read full answer

2. What are the key features of Micronaut?

Micronaut's defining features all stem from doing work at build time instead of runtime. Compile-time dependency injection - beans and their wiring are resolved by an annotation processor, not reflection....

Read full answer

3. What is dependency injection in Micronaut?

Dependency injection (DI) in Micronaut is the pattern where a class declares what it needs through its constructor or fields instead of creating those dependencies itself, and the framework supplies them. A class becomes injectable by annotating it with a...

Read full answer

4. What are Micronaut beans?

A bean in Micronaut is any class the ApplicationContext manages: it decides when to create it, what scope it lives in, and what gets injected into it. A class becomes a bean by carrying a scope annotation ( @Singleton ,...

Read full answer

5. What is the purpose of the @Singleton annotation in Micronaut?

@Singleton tells Micronaut to create exactly one instance of the annotated class for the lifetime of the ApplicationContext and hand out that same instance to every injection point. It's the most commonly used scope for services, repositories, and clients because...

Read full answer

6. What are the types of bean scopes in Micronaut?

Micronaut ships several built-in scopes that control how many instances of a bean exist and how long they live. Scope Lifecycle @Singleton One shared instance for the whole application context....

Read full answer

7. How do you create a Micronaut application?

The fastest path is Micronaut Launch (launch.micronaut.io) or the equivalent mn create-app CLI command, which scaffolds a project with your chosen build tool (Gradle or Maven), language (Java, Kotlin, Groovy), and starter features such as Micronaut Data or Security. mn...

Read full answer

8. What is Micronaut Launch?

Micronaut Launch is the official web-based and API-driven project generator for Micronaut applications, available at launch.micronaut.io. It's the modern successor to the older Micronaut CLI workflow for starting new projects, similar in spirit to Spring Initializr....

Read full answer

9. What is ahead-of-time (AOT) compilation in Micronaut?

In Micronaut, AOT compilation refers to the work its annotation processors do during the build, before the JVM ever starts the application, to precompute everything that other frameworks typically figure out at runtime. During compilation, Micronaut analyzes annotated classes and...

Read full answer

10. What are Micronaut controllers?

A Micronaut controller is a bean annotated with @Controller that maps incoming HTTP requests to methods, similar in role to a Spring MVC @RestController . The class-level @Controller("/orders") sets a base path, and method-level annotations such as @Get , @Post...

Read full answer

11. How do you define a REST endpoint in Micronaut?

You define a REST endpoint by annotating a controller method with the appropriate HTTP-verb annotation and mapping any path or body data to method parameters. @Controller ( "/books" ) public class BookController { @Get ( "/{isbn}" ) public HttpResponse <...

Read full answer

12. What is the purpose of the @Inject annotation in Micronaut?

@Inject marks a constructor, field, or setter method as a point where Micronaut should supply a dependency from the ApplicationContext rather than the class constructing it itself. On a constructor, it's actually optional when there's only one constructor - Micronaut...

Read full answer

13. What are Micronaut configuration properties?

Configuration properties in Micronaut are externalized values, such as database URLs, timeouts, or feature flags, that live outside your code in files like application.yml , environment variables, or command-line arguments, and get bound into typed Java objects. The simplest way...

Read full answer

14. Describe how application.yml is used in Micronaut?

application.yml is Micronaut's default configuration file, read from the classpath at startup and merged with any environment-specific variants such as application-dev.yml or application-test.yml based on the active environments. micronaut: application: name: orders-service datasources: default:

Read full answer

15. What is the Micronaut HTTP Client?

The Micronaut HTTP Client is a built-in, non-blocking client for calling other HTTP services, available in both a low-level programmatic form and a declarative form. The low-level HttpClient is injected and used directly: @Inject HttpClient httpClient; Mono < String >...

Read full answer

16. Why is Micronaut faster at startup than traditional Spring Boot applications?

The gap comes down to when the expensive work happens. Traditional Spring Boot relies heavily on classpath scanning and reflection at startup to discover components, resolve dependency graphs, and build AOP proxies, and all of that costs CPU time and...

Read full answer

17. Why does Micronaut avoid using reflection?

Reflection is flexible but expensive: it involves runtime introspection of classes, is slower than direct method calls, increases memory usage for metadata, and, critically for native images, GraalVM can't statically analyze reflective calls without explicit configuration, making apps harder to...

Read full answer

18. How does Micronaut achieve compile-time dependency injection?

Micronaut hooks into the standard Java annotation processing API, the same mechanism used by tools like Lombok, during compilation. Its processor scans source for DI-related annotations such as @Singleton , @Inject , @Prototype , @Factory , and qualifiers, and builds...

Read full answer

19. What is the difference between Micronaut and Spring Boot?

Micronaut Spring Boot Dependency injection resolved at compile time via annotation processing. Dependency injection resolved at runtime via classpath scanning and reflection.

Read full answer

20. What is the difference between @Singleton and @Prototype scope in Micronaut?

@Singleton @Prototype One shared instance for the entire ApplicationContext. A new instance created on every injection or bean lookup....

Read full answer

21. When should you use @Factory in Micronaut?

Use @Factory when you need to produce a bean that Micronaut can't construct directly, typically because it comes from a third-party class you don't control, needs custom construction logic, or requires multiple related beans built from shared setup. @Factory public...

Read full answer

22. How does Micronaut Data work?

Micronaut Data is a database access toolkit that generates repository implementations at compile time, the same way Micronaut generates DI metadata: there's no runtime proxy, no reflection-based query building, and no Hibernate-style session/proxy machinery involved by default. You define a...

Read full answer

23. What is the difference between Micronaut Data JDBC and Micronaut Data JPA?

Micronaut Data JDBC Micronaut Data JPA Executes plain SQL directly against the database with no persistence context. Uses Hibernate/JPA underneath, with an entity manager and persistence context....

Read full answer

24. How do you implement bean validation in Micronaut?

Micronaut integrates the Jakarta Bean Validation API directly, and true to form, validates using compile-time generated code rather than runtime reflection over annotations. public class CreateOrderRequest { @NotBlank private String customerId; @Min ( 1 ) private int quantity; } @Post...

Read full answer

25. How does Micronaut implement AOP (aspect-oriented programming)?

Micronaut implements AOP the same way it implements DI: at compile time, not through runtime bytecode generation. You define an interceptor by implementing MethodInterceptor and create a custom annotation marked with @Around to trigger it....

Read full answer

26. How does Micronaut support reactive programming?

Micronaut's HTTP server and client are non-blocking and reactive by default, built on Netty's event-loop model, so controller and client methods can return reactive types instead of blocking the request thread. @Get ( "/orders/{id}" ) public Mono < Order >...

Read full answer

27. What is the difference between a Micronaut declarative HTTP client and the low-level HttpClient?

Declarative @Client Low-level HttpClient Defined as an interface with HTTP annotations; Micronaut generates the implementation. Used programmatically by calling methods like retrieve() or exchange() directly.

Read full answer

28. How do you implement client-side load balancing in Micronaut?

Client-side load balancing in Micronaut happens automatically when a @Client targets a logical service ID instead of a fixed URL, combined with a service discovery source that tells Micronaut which instances currently exist. @Client ( "payments-service" ) public interface PaymentClient...

Read full answer

29. What is Micronaut's service discovery mechanism?

Service discovery in Micronaut lets services find each other by logical name instead of hardcoded addresses, and it's pluggable rather than tied to one product. Out of the box, Micronaut supports Consul and Eureka as discovery servers, plus native discovery...

Read full answer

30. How do you implement retries and circuit breakers in Micronaut?

Micronaut Retry provides both behaviors as declarative annotations built on its AOP mechanism, so no manual try/catch retry loops are needed. @Client ( "payments-service" ) public interface PaymentClient { @Retryable (attempts = "3" , delay = "500ms" ) @CircuitBreaker (reset...

Read full answer

31. What is the difference between @Client and @Controller in Micronaut?

@Controller @Client Defines endpoints your application exposes to callers. Defines endpoints your application calls on another service....

Read full answer

32. How do you handle exceptions globally in a Micronaut application?

Micronaut handles global exceptions through ExceptionHandler beans rather than a single catch-all annotation on a controller class. @Produces @Singleton @Requires (classes = OrderNotFoundException .

Read full answer

33. What is the purpose of Micronaut's BeanContext and ApplicationContext?

BeanContext is Micronaut's core IoC container: it holds bean definitions, resolves dependencies, manages scopes, and lets you look up beans programmatically via getBean() . It's usable on its own for lightweight, non-HTTP scenarios like CLI tools....

Read full answer

34. How does Micronaut support GraalVM native image compilation?

Micronaut was designed with GraalVM native image in mind from early on, which matters because native-image's static analysis struggles with unconstrained reflection, dynamic proxies, and classpath scanning, exactly the things Micronaut avoids by generating DI and AOP metadata at compile...

Read full answer

35. When would you choose Micronaut over Spring Boot for a new project?

Micronaut tends to be the stronger choice when startup time and memory footprint directly affect cost or user experience: serverless functions billed per invocation, high-density container deployments where you're packing many small services per node, and CLI tools that need...

Read full answer

36. Explain the internal working of Micronaut's compile-time dependency injection?

Micronaut's DI pipeline runs almost entirely during the Java, Kotlin, or Groovy compilation step, using the standard annotation processing API. graph TD A[Source classes with singleton, inject, factory annotations] --> B[Micronaut annotation processor] B --> C[In-memory bean model: constructors,

Read full answer

37. Explain the lifecycle of a Micronaut bean?

A Micronaut bean moves through a well-defined set of stages between being requested and being destroyed, and several of them are extension points you can hook into. graph TD A[Bean requested from ApplicationContext] --> B[Dependencies resolved via generated BeanDefinition] B...

Read full answer

38. Explain the execution flow of an HTTP request in Micronaut?

An incoming HTTP request flows through several stages before a response is written back, all on Micronaut's non-blocking Netty pipeline. sequenceDiagram participant Client participant Netty as Netty Event Loop participant Router participant Filters as HTTP Filters participant Controller participa

Read full answer

39. How can you optimize Micronaut application startup time further?

Even though Micronaut starts fast by default, a few levers push it further, especially for latency-sensitive targets like serverless functions. Prefer eager singletons sparingly: mark only truly startup-critical beans @Context ; lazy initialization of the rest avoids unnecessary work on...

Read full answer

40. How do you troubleshoot slow or failing GraalVM native image builds in Micronaut?

Start by reading the native-image build log carefully rather than guessing; most failures fall into a handful of recurring categories: missing reflection/resource configuration for a third-party library, unsupported dynamic class loading, or a dependency that simply isn't native-image-ready. Chec

Read full answer

41. What is the difference between Micronaut's bean introspection and Java reflection?

BeanIntrospection is Micronaut's compile-time alternative to reflective bean inspection: it lets you read and write properties, and get annotation metadata, without ever calling into java.lang.reflect at runtime. @Introspected public class Order { private String id; // getters / setters }...

Read full answer

42. Explain the internal working of Micronaut's AOP proxy generation?

Micronaut generates AOP proxies as ordinary subclasses at compile time, rather than the runtime bytecode generation used by CGLIB or JDK dynamic proxies. graph TD A[Method annotated with an Around-based meta annotation] --> B[Annotation processor detects interceptor binding] B -->...

Read full answer

43. Explain the internal working of Micronaut Data repository method generation?

Micronaut Data turns a repository interface into a concrete implementation entirely at compile time, without generating SQL strings at runtime or relying on a persistence framework's dynamic proxy. graph TD A[Repository interface extends CrudRepository] --> B[Processor parses method signatures] B

Read full answer

44. How do you implement distributed tracing across Micronaut microservices?

Micronaut Tracing integrates with OpenTelemetry, and historically Zipkin/Brave and Jaeger via OpenTracing, to automatically propagate and record trace context across HTTP calls between services, without instrumenting every method by hand. sequenceDiagram participant OrderSvc as Order Service part

Read full answer

45. How do you secure a Micronaut application with JWT authentication?

Micronaut Security provides built-in JWT support: add the security-jwt module dependency, configure a signature secret or a JWKS endpoint for asymmetric keys, and Micronaut handles validating incoming bearer tokens automatically. micronaut: security: authentication: bearer token: jwt: signatures:

Read full answer

46. How does Micronaut resolve configuration properties across multiple environments?

Micronaut resolves configuration through its Environment abstraction, which merges multiple property sources by a defined precedence order rather than picking just one file. Command-line arguments (highest precedence).

Read full answer

47. Explain the internal working of Micronaut's event publishing system?

Micronaut's event system is a lightweight, synchronous-by-default pub/sub mechanism wired through the same compile-time DI infrastructure as everything else; there's no separate runtime event bus with reflective listener discovery. graph TD A[Bean injects ApplicationEventPublisher] --> B[publishE

Read full answer

48. How do you troubleshoot excessive memory usage in a Micronaut native image at runtime?

Native image memory issues usually trace back to a handful of causes distinct from typical JVM heap tuning, since native images manage memory somewhat differently, with no dynamic class loading and different GC defaults. Check the GC in use....

Read full answer

49. How do you troubleshoot a Micronaut bean that fails to inject due to ambiguous qualifiers?

An ambiguous injection error, where Micronaut reports multiple candidate beans for a single injection point, happens when more than one bean implements the same injected type and none is marked as the one to prefer. public interface NotificationSender {} @Singleton...

Read full answer

50. Explain how Micronaut's compile-time architecture influences microservice design decisions in real projects?

Choosing Micronaut isn't just a library swap; its compile-time-first design pushes several architectural decisions that teams building microservices end up making differently than they might with a purely runtime-reflective framework. Because startup is cheap, services can be sized smaller and...

Read full answer

«
»

Comments & Discussions