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;
}
DubboReference,
ReferenceBeanBuilder| Constructor and Description |
|---|
ReferenceBean() |
ReferenceBean(Map<String,Object> referenceProps) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
void |
destroy() |
String |
getGroup()
The group of the service
|
String |
getId() |
Class<?> |
getInterfaceClass()
The interface of this ReferenceBean, for injection purpose
|
String |
getKey() |
T |
getObject()
Create bean instance.
|
Class<?> |
getObjectType() |
org.springframework.beans.MutablePropertyValues |
getPropertyValues() |
ReferenceConfig |
getReferenceConfig() |
Map<String,Object> |
getReferenceProps() |
String |
getServiceInterface()
The interface of remote service
|
String |
getVersion()
The version of the service
|
boolean |
isSingleton() |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setBeanClassLoader(ClassLoader classLoader) |
void |
setBeanName(String name) |
void |
setId(String id) |
void |
setKeyAndReferenceConfig(String key,
ReferenceConfig referenceConfig) |
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
setApplicationContext in interface org.springframework.context.ApplicationContextAwarepublic void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAwarepublic void setBeanName(String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic T getObject()
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.
getObject in interface org.springframework.beans.factory.FactoryBean<T>DubboConfigBeanInitializer,
ReferenceBeanManager.initReferenceBean(ReferenceBean),
DubboBeanDefinitionParser.configReferenceBean(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.factory.config.BeanDefinition)public Class<?> getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBean<T>@Parameter(excluded=true) public boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBean<T>public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeanpublic String getId()
public void setId(String id)
public Class<?> getInterfaceClass()
public String getServiceInterface()
public String getGroup()
public String getVersion()
public String getKey()
public org.springframework.beans.MutablePropertyValues getPropertyValues()
public ReferenceConfig getReferenceConfig()
public void setKeyAndReferenceConfig(String key, ReferenceConfig referenceConfig)
Copyright © 2011–2020 The Apache Software Foundation. All rights reserved.