Govt. Exams
Entrance Exams
Stereotype annotations (@Service, @Repository, @Controller) enable classpath component scanning and convey the architectural role of the class.
Prototype scope creates a new bean instance each time it's requested, unlike singleton which creates only one instance for the entire application.
Spring supports singleton, prototype, request, session, application, and websocket scopes. 'Eternal' is not a valid scope in Spring Framework.
ApplicationContext is the core container that instantiates, configures, and manages beans. It also resolves dependencies and manages bean lifecycle.
@Component, @Service, @Repository, and @Controller are all stereotype annotations that mark classes as Spring Beans. @Bean is used for method-level bean definition.
Spring raises NoUniqueBeanDefinitionException when ambiguity exists. Use @Primary or @Qualifier to resolve the ambiguity.
DI reduces tight coupling between classes, making code more maintainable, testable, and flexible for changes or mock implementations during testing.
@Component is a generic stereotype, while @Service is a specialized annotation indicating the class contains business logic, improving code readability.
Singleton beans are instantiated once per Spring container and reused for the application's lifetime, making them memory-efficient for stateless objects.
@Autowired is used for dependency injection, allowing Spring to automatically resolve and inject bean dependencies without explicit configuration.