How does ApplicationContextAware work in Spring?

后端 未结 4 543
醉话见心
醉话见心 2020-12-22 16:42

In spring, if a bean implements ApplicationContextAware, then it is able to access the applicationContext. Therefore it is able to get other beans.

4条回答
  •  一个人的身影
    2020-12-22 17:23

    Interface to be implemented by any object that wishes to be notified of the ApplicationContext that it runs in.

    above is excerpted from the Spring doc website https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/ApplicationContextAware.html.

    So, it seemed to be invoked when Spring container has started, if you want to do something at that time.

    It just has one method to set the context, so you will get the context and do something to sth now already in context I think.

提交回复
热议问题