Package org.apache.dubbo.config.spring
Class ReferenceBean<T>
java.lang.Object
org.apache.dubbo.config.spring.ReferenceBean<T>
- All Implemented Interfaces:
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<T>,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware
public class ReferenceBean<T>
extends Object
implements org.springframework.beans.factory.FactoryBean<T>, 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.
@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;
}
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()getGroup()The group of the servicegetId()Class<?> The interface of this ReferenceBean, for injection purposegetKey()Create bean instance.Class<?> org.springframework.beans.MutablePropertyValuesThe interface of remote serviceThe version of the servicebooleanvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanName(String name) voidvoidsetInterfaceClass(Class<?> interfaceClass) voidsetInterfaceName(String interfaceName) voidsetKeyAndReferenceConfig(String key, ReferenceConfig referenceConfig) voidsetReferencePropsJson(String referencePropsJson) It is only used in native scenarios to get referenceProps because attribute is not passed by BeanDefinition by default.
-
Constructor Details
-
ReferenceBean
public ReferenceBean() -
ReferenceBean
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
getObject
Create bean instance. Why we need a lazy proxy?
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.
(This has already been resolved by decorating the BeanDefinition:DubboBeanDefinitionParser.configReferenceBean(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.factory.config.BeanDefinition))
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.- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<T>- See Also:
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<T>
-
isSingleton
@Parameter(excluded=true) public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<T>
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
getId
-
setId
-
getInterfaceClass
The interface of this ReferenceBean, for injection purpose- Returns:
-
getServiceInterface
The interface of remote service -
getGroup
The group of the service -
getVersion
The version of the service -
getKey
-
getReferenceProps
-
getPropertyValues
public org.springframework.beans.MutablePropertyValues getPropertyValues() -
getReferenceConfig
-
setKeyAndReferenceConfig
-
setInterfaceClass
-
setInterfaceName
-
setReferencePropsJson
It is only used in native scenarios to get referenceProps because attribute is not passed by BeanDefinition by default.- Parameters:
referencePropsJson-
-