spring中自定义组件需要使用spring的底层组件时,可以通过自定义组件实现相关XxxAware接口,重写其中的方法进而实现。

例如:自定义一个组件,该组件中需要使用ApplicationContext、BeanFactory属性,那么我们就可以通过实现ApplicationContextAware、BeanFactoryAware接口实现。会自动set对应的属性,直接使用Spring底层组件。

The use of the Aware interface in spring, setting the BeanFactory

Aware interface

常见的spring Aware接口

83567-2g06zdq4lzm.png

标签: spring


阿里云优惠主机

添加新评论

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。