zoukankan      html  css  js  c++  java
  • 16、spring注解学习(自动装配)——Aware注入Spring底层组件&原理

    自动装配-Aware注入Spring底层组件&原理

    • Aware 接口,提供了类似回调函数的功能
    • 自定义组件想要使用Spring 容器底层的一些组件(Application Context,Bean Factory);自定义组件需要实现xxxAware接口;在创建对象的时候,会调用接口规定的方法注入相关组件
      package org.springframework.beans.factory;
      
      public interface Aware {
      
      }

      ApplicationContextAware 自动注入IOC容器

      package org.springframework.context;
      
      import org.springframework.beans.BeansException;
      import org.springframework.beans.factory.Aware;
      
      public interface ApplicationContextAware extends Aware {
      
          void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
      
      }

      ApplicationEventPublisherAware 注入事件派发器

      package org.springframework.context;
      
      import org.springframework.beans.factory.Aware;
      
      public interface ApplicationEventPublisherAware extends Aware {
      
          void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher);
      
      }

      BeanClassLoaderAware 类加载器

      package org.springframework.beans.factory;
      
      public interface BeanClassLoaderAware extends Aware {
      
          void setBeanClassLoader(ClassLoader classLoader);
      
      }

      BeanFactoryAware Bean工厂

      package org.springframework.beans.factory;
      
      import org.springframework.beans.BeansException;
      public interface BeanFactoryAware extends Aware {
      
          void setBeanFactory(BeanFactory beanFactory) throws BeansException;
      
      }

      BeanNameAware Bean名字

      package org.springframework.beans.factory;
      
      public interface BeanNameAware extends Aware {
      
          void setBeanName(String name);
      
      }

      EmbeddedValueResolverAware Embedded值解析器

      package org.springframework.context;
      
      import org.springframework.beans.factory.Aware;
      import org.springframework.util.StringValueResolver;
      
      public interface EmbeddedValueResolverAware extends Aware {
      
          void setEmbeddedValueResolver(StringValueResolver resolver);
      
      }

      EnvironmentAware 环境

      package org.springframework.context;
      
      import org.springframework.beans.factory.Aware;
      import org.springframework.core.env.Environment;
      
      public interface EnvironmentAware extends Aware {
      
          void setEnvironment(Environment environment);
      
      }

      ImportAware 导入相关的

      package org.springframework.context.annotation;
      
      import org.springframework.beans.factory.Aware;
      import org.springframework.core.type.AnnotationMetadata;
      
      public interface ImportAware extends Aware {
      
          void setImportMetadata(AnnotationMetadata importMetadata);
      
      }

      LoadTimeWeaverAware 导入相关的

      package org.springframework.context.weaving;
      
      import org.springframework.beans.factory.Aware;
      import org.springframework.instrument.classloading.LoadTimeWeaver;
      
      public interface LoadTimeWeaverAware extends Aware {
      
          void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver);
      
      }

      MessageSourceAware 国际化

      package org.springframework.context;
      
      import org.springframework.beans.factory.Aware;
      
      public interface MessageSourceAware extends Aware {
      
          void setMessageSource(MessageSource messageSource);
      
      }

       NotificationPublisherAware 发送通知的支持

      package org.springframework.jmx.export.notification;
      
      import org.springframework.beans.factory.Aware;
      
      public interface NotificationPublisherAware extends Aware {
      
          void setNotificationPublisher(NotificationPublisher notificationPublisher);
      
      }

      ResourceLoaderAware 资源加载器

      package org.springframework.context;
      
      import org.springframework.beans.factory.Aware;
      import org.springframework.core.io.ResourceLoader;
      
      public interface ResourceLoaderAware extends Aware {
      
          void setResourceLoader(ResourceLoader resourceLoader);
      
      }

      得到结果:

  • 相关阅读:
    禁止页面被复制和禁止右键,一段样式一段JS就行了,无需复杂设定!
    你不知道的DIV+CSS的命名规则
    帝国cms提高网站网页打开速度的手段
    帝国cms网站管理系统之安全设置最优化分享
    渗透测试===使用BURPSUIT暴力破解某网站的手机验证码
    并发、并行、同步、异步、多线程的区别?
    python基础===一行 Python 代码实现并行(转)
    python目前安装的包备份
    jmeter,测登录,要不要过滤掉JS,CSS等请求?感觉过滤掉了压出来的数据就不真实?
    几个网站
  • 原文地址:https://www.cnblogs.com/lyh233/p/12450388.html
Copyright © 2011-2022 走看看