Java / Micronaut Interview questions
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.
ApplicationContext extends BeanContext and adds everything needed for a full application: environment and property resolution (application.yml, environment variables, command-line args), profile/environment detection (dev, test, prod), and integration with configuration sources like Consul or AWS Parameter Store.
ApplicationContext ctx = ApplicationContext.run(); OrderService service = ctx.getBean(OrderService.class);
In practice, almost every real Micronaut application uses ApplicationContext, since even simple services need externalized configuration; BeanContext mainly shows up in embedded or highly constrained use cases where configuration resolution isn't needed at all.
More Related questions...