Spring's life cycle

Spring's life cycle

  • 1. Call the Bean's constructor (or factory method) to instantiate the Bean.
  • 2. Assign values ​​to the member variables of the Bean.
  • 3. If the Bean implements BeanNameAware, call the Bean's setBeanName method.
  • 4. If the Bean implements BeanFactoryAware, call the Bean's setBeanFactory method.
  • 5. If the Bean implements ApplicationContextAware, call the Bean's setApplicationContext method.
  • 6. If a BeanPostProcessor is configured in the container, call the postProcessBeforeInitialization method of the BeanPostProcessor (if there are multiple BeanPostProcessors, call the postProcessBeforeInitialization method of each BeanPostProcessor).
  • 6. If the Bean implements InitializingBean, call the Bean's afterPropertiesSet method.
  • 7. If the Bean is configured with the init-method method, call the Bean method configured by the init-method.
  • 8. If a BeanPostProcessor is configured in the container, call the postProcessAfterInitialization method of the BeanPostProcessor. (If there are multiple BeanPostProcessors, call the postProcessAfterInitialization method of each BeanPostProcessor).
  • 9, Bean is in a ready-to-use state.
  • 10. The Spring container is closed.
  • 11. If the Bean implements DisposableBean, call the destroy method of the Bean.
  • 12. If the Bean is configured with the destroy-method method, call the method of the Bean configured by the destroy-method.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325527755&siteId=291194637