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

What is the typical Bean life cycle in Spring Bean Factory Container?

Câu trả lời

The typical bean life cycle in a Spring Bean Factory Container involves several key stages that manage the creation, use, and destruction of beans within the Spring application context. Here's a detailed breakdown of each stage:

  1. Bean Definition: The process begins when the Spring container reads the bean definitions from a configuration source (XML, Java annotations, or Java code). These definitions specify the bean's properties, constructor arguments, and other configuration settings that are needed to create the bean.

  2. Bean Instantiation: The Spring container then instantiates the bean. This is typically done by calling the constructor of the bean's class. If the bean has a no-argument constructor and is configured for dependency injection, this constructor will be used.

  3. Dependency Injection: Once the bean is instantiated, the Spring container injects dependencies defined in the bean configuration. This can be done through setter methods, constructor arguments, or directly through field access.

  4. Set Bean Name and Other Attributes: If the bean implements the BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, or ApplicationContextAware interfaces, the container will set the necessary attributes like bean name, class loader, bean factory, and application context respectively.

  5. Pre-initialization (Bean Post Processors): Before the bean is fully initialized, the Spring container allows BeanPostProcessors to modify the new bean instance. This is a powerful feature that can, for example, wrap the bean with a proxy to enable aspects such as transactions or security.

  6. Initialization: If the bean implements the InitializingBean interface, its afterPropertiesSet method will ...

middle

middle

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

junior

Explain @RequestMapping annotation.

junior

What are ORM's Spring supports?

senior

What are the disadvantages of using Reactive Streams?

Bình luận

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

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