Spring ApplicationContextAware

版权声明:转载请注明来源 https://blog.csdn.net/genghaihua/article/details/89423912

但在某些特殊的情况下,Bean需要实现某个功能,但该功能必须借助于Spring容器才能实现,此时就必须让该Bean先获取Spring容器,然后借助于Spring容器实现该功能。为了让Bean获取它所在的Spring容器,可以让该Bean实现ApplicationContextAware接口。

Implementing this interface makes sense for example when an object
* requires access to a set of collaborating beans. Note that configuration
* via bean references is preferable to implementing this interface just
* for bean lookup purposes.

猜你喜欢

转载自blog.csdn.net/genghaihua/article/details/89423912