Java / Micronaut Interview questions
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.
For a @Singleton, steps A through G happen once, at either eager startup for @Context-scoped beans or on first lookup for lazily initialized singletons; for @Prototype, the whole sequence repeats on every injection.
@PostConstruct and @PreDestroy give you hooks for setup and cleanup work, such as opening a connection pool or starting a background thread, and cleanly closing it, respectively, while implementing BeanCreatedEventListener<T> lets other beans observe or even wrap or replace an instance right after it's created, which is how some AOP-adjacent and instrumentation features are implemented.
More Related questions...