Java / Micronaut Interview questions
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 most of these components are stateless and safe to share. The instance is created eagerly or lazily depending on configuration, and it's destroyed when the context shuts down, triggering any @PreDestroy method on the bean.
@Singleton is functionally similar to Spring's default singleton scope, but in Micronaut the scope decision is baked into the compiled bean metadata rather than tracked by a runtime registry.
More Related questions...