什么是spring aware

2025-04-09 14:06:34

1、第一步在开发中,不可避免需要使用到spring容器本身的功能和资源,这时bean需要意识到spring容器的存在,才能使用spring提供的资源,这就是所谓的spring aware

什么是spring aware

2、第二步spring Aware的目的是为了将bean获得spring容器的服务,appli罕铞泱殳cationContext接口集成了MessageSource接口、applicationEvenPublisher接口 ResourceLoader接口

什么是spring aware

3、第三步Bean集成了ApplicationContextArea可以获得spring容器的所有服务,但是原则上还是用到什么接口,就实现什么接口

什么是spring aware

4、第四步上一步定义了spring容器的工厂类,在项目实际使用中,如下图:

什么是spring aware

5、第五步实现BeanNameAware/ResourceLoaderAware接口,可以获得幞洼踉残Bean名称和加载的服务实现Resource讣嘬铮篌LoaderAware需要重写 setresourceLoader实现beanNameAware需要重写setBeanName方法

什么是spring aware
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:85
  • 阅读量:31
  • 阅读量:75
  • 阅读量:53
  • 阅读量:70
  • 猜你喜欢