Câu hỏi phỏng vấn Spring
Câu hỏi

What is the difference between Bean Factory and Application Context?

Câu trả lời

The difference between BeanFactory and ApplicationContext in Spring Framework is primarily in terms of the features and capabilities they offer for managing beans within the Spring Inversion of Control (IoC) container.

BeanFactory

  • Basic IoC Container: BeanFactory is the root interface for accessing the Spring container and provides basic Inversion of Control functionalities.
  • Lazy Initialization: By default, beans managed by BeanFactory are lazily initialized. This means that the container will create a bean instance only when you explicitly request it using the getBean() method.
  • Resource Handling: It uses the Resource interface to access resources but provides minimal support beyond that.
  • Limited Features: BeanFactory is a simpler container offering basic support for Dependency Injection and is suitable for lightweight applications or resource-constrained environments like mobile devices or applets[1][2][3][4][5][6][7][8].

ApplicationContext

  • Advanced IoC Container: ApplicationContext is a sub-interface of BeanFactory and provides all the features of BeanFactory with additional enterprise-specific functionalities.
  • Eager Initialization: ApplicationContext eagerly initializes singleton beans upon container startup. This approach is useful for detecting bean configuration issues early in the application lifecycle.
  • Advanced Features: It supports internationalization, event propagation, application layer specific contexts (such as WebApplicationContext for web applications), and more.
  • Annotation Support: ApplicationContext supports annotation-based configuration, which allows for more modern and less verbose configuration compared to XML.
  • Autowiring: It can automatically detect and configure bean post-processors, factory post-processors, and beans that implement certain aware interfaces[1][2][3][4][5][6][7][8].

Key Differences

  • Bean Instantiation: BeanFactory instantiates a bean when getBean() is called (lazy ...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What are the different modules in Spring framework?

junior

What is default scope of bean in Spring framework?

senior

What’s the difference between @Component, @Controller, @Repository & @Service annotations in
Spring?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào