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;
}
| 构造器和说明 |
|---|
ReferenceBean() |
ReferenceBean(Map<String,Object> referenceProps) |
| 限定符和类型 | 方法和说明 |
|---|---|
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 在接口中 org.springframework.context.ApplicationContextAwarepublic void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader 在接口中 org.springframework.beans.factory.BeanClassLoaderAwarepublic void setBeanName(String name)
setBeanName 在接口中 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 在接口中 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 在接口中 org.springframework.beans.factory.FactoryBean<T>@Parameter(excluded=true) public boolean isSingleton()
isSingleton 在接口中 org.springframework.beans.factory.FactoryBean<T>public void afterPropertiesSet()
throws Exception
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanExceptionpublic void destroy()
destroy 在接口中 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.