类 ReferenceBean<T>

  • 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

    public class ReferenceBean<T>
    extends Object
    implements org.springframework.beans.factory.FactoryBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

    Spring FactoryBean for ReferenceConfig.

    Step 1: Register ReferenceBean in Java-config class:
     @Configuration
     public class ReferenceConfiguration {
         @Bean
         @DubboReference(group = "demo")
         public ReferenceBean<HelloService> helloService() {
             return new ReferenceBean();
         }
    
         // As GenericService
         @Bean
         @DubboReference(group = "demo", interfaceClass = HelloService.class)
         public ReferenceBean<GenericService> genericHelloService() {
             return new ReferenceBean();
         }
     }
     
    Or register ReferenceBean in xml:
     <dubbo:reference id="helloService" interface="org.apache.dubbo.config.spring.api.HelloService"/>
     <!-- As GenericService -->
     <dubbo:reference id="genericHelloService" interface="org.apache.dubbo.config.spring.api.HelloService" generic="true"/>
     
    Step 2: Inject ReferenceBean by @Autowired
     public class FooController {
         @Autowired
         private HelloService helloService;
    
         @Autowired
         private GenericService genericHelloService;
     }
     
    另请参阅:
    DubboReference, ReferenceBeanBuilder
    • 构造器详细资料

      • ReferenceBean

        public ReferenceBean()
      • ReferenceBean

        public ReferenceBean​(Map<String,​Object> referenceProps)
    • 方法详细资料

      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)
        指定者:
        setApplicationContext 在接口中 org.springframework.context.ApplicationContextAware
      • setBeanClassLoader

        public void setBeanClassLoader​(ClassLoader classLoader)
        指定者:
        setBeanClassLoader 在接口中 org.springframework.beans.factory.BeanClassLoaderAware
      • setBeanName

        public void setBeanName​(String name)
        指定者:
        setBeanName 在接口中 org.springframework.beans.factory.BeanNameAware
      • getObject

        public Object getObject()
        Create bean instance.

        When Spring searches beans by type, if Spring cannot determine the type of a factory bean, it may try to initialize it. The ReferenceBean is also a FactoryBean.

        In addition, if some ReferenceBeans are dependent on beans that are initialized very early, and dubbo config beans are not ready yet, there will be many unexpected problems if initializing the dubbo reference immediately.

        When it is initialized, only a lazy proxy object will be created, and dubbo reference-related resources will not be initialized.
        In this way, the influence of Spring is eliminated, and the dubbo configuration initialization is controllable.

        Dubbo config beans are initialized in DubboConfigInitializationPostProcessor.
        The actual references will be processing in DubboBootstrap.referServices().

        指定者:
        getObject 在接口中 org.springframework.beans.factory.FactoryBean<T>
        另请参阅:
        DubboConfigInitializationPostProcessor, DubboBootstrap
      • getObjectType

        public Class<?> getObjectType()
        指定者:
        getObjectType 在接口中 org.springframework.beans.factory.FactoryBean<T>
      • isSingleton

        @Parameter(excluded=true)
        public boolean isSingleton()
        指定者:
        isSingleton 在接口中 org.springframework.beans.factory.FactoryBean<T>
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        Exception
      • destroy

        public void destroy()
        指定者:
        destroy 在接口中 org.springframework.beans.factory.DisposableBean
      • getId

        public String getId()
      • setId

        public void setId​(String id)
      • getInterfaceClass

        public Class<?> getInterfaceClass()
      • getActualInterface

        public Class getActualInterface()
      • getGroup

        public String getGroup()
      • getVersion

        public String getVersion()
      • getKey

        public String getKey()
      • getPropertyValues

        public org.springframework.beans.MutablePropertyValues getPropertyValues()
      • setKeyAndReferenceConfig

        public void setKeyAndReferenceConfig​(String key,
                                             ReferenceConfig referenceConfig)