Resolve conflicts of spring bean (#12474)
* Resolve conflicts of spring bean * Fix import * Fix uts * Fix uts * Fix uts
This commit is contained in:
parent
04d132fee1
commit
a758a1e7e0
|
|
@ -32,8 +32,8 @@ import org.apache.dubbo.config.ProviderConfig;
|
|||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.nested.AggregationConfig;
|
||||
import org.apache.dubbo.config.nested.PrometheusConfig;
|
||||
import org.apache.dubbo.config.nested.HistogramConfig;
|
||||
import org.apache.dubbo.config.nested.PrometheusConfig;
|
||||
import org.apache.dubbo.config.spring.Constants;
|
||||
import org.apache.dubbo.config.spring.ReferenceBean;
|
||||
import org.apache.dubbo.config.spring.ServiceBean;
|
||||
|
|
@ -103,9 +103,11 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
|
|||
if (StringUtils.isNotEmpty(configId)) {
|
||||
beanDefinition.getPropertyValues().addPropertyValue("id", configId);
|
||||
}
|
||||
// get id from name
|
||||
|
||||
String configName = "";
|
||||
// get configName from name
|
||||
if (StringUtils.isEmpty(configId)) {
|
||||
configId = resolveAttribute(element, "name", parserContext);
|
||||
configName = resolveAttribute(element, "name", parserContext);
|
||||
}
|
||||
|
||||
String beanName = configId;
|
||||
|
|
@ -113,13 +115,14 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
|
|||
// generate bean name
|
||||
String prefix = beanClass.getName();
|
||||
int counter = 0;
|
||||
beanName = prefix + "#" + counter;
|
||||
beanName = prefix + (StringUtils.isEmpty(configName) ? "#" : ("#" + configName + "#")) + counter;
|
||||
while (parserContext.getRegistry().containsBeanDefinition(beanName)) {
|
||||
beanName = prefix + "#" + (counter++);
|
||||
beanName = prefix + (StringUtils.isEmpty(configName) ? "#" : ("#" + configName + "#")) + (counter++);
|
||||
}
|
||||
}
|
||||
beanDefinition.setAttribute(BEAN_NAME, beanName);
|
||||
|
||||
|
||||
if (ProtocolConfig.class.equals(beanClass)) {
|
||||
// for (String name : parserContext.getRegistry().getBeanDefinitionNames()) {
|
||||
// BeanDefinition definition = parserContext.getRegistry().getBeanDefinition(name);
|
||||
|
|
@ -184,7 +187,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
|
|||
* For 'provider' 'protocol' 'registry', keep literal value (should be id/name) and set the value to 'registryIds' 'providerIds' protocolIds'
|
||||
* The following process should make sure each id refers to the corresponding instance, here's how to find the instance for different use cases:
|
||||
* 1. Spring, check existing bean by id, see{@link ServiceBean#afterPropertiesSet()}; then try to use id to find configs defined in remote Config Center
|
||||
* 2. API, directly use id to find configs defined in remote Config Center; if all config instances are defined locally, please use {@link ServiceConfig#setRegistries(List)}
|
||||
* 2. API, directly use id to find configs defined in remote Config Center; if all config instances are defined locally, please use {@link org.apache.dubbo.config.ServiceConfig#setRegistries(List)}
|
||||
*/
|
||||
beanDefinition.getPropertyValues().addPropertyValue(beanProperty + "Ids", value);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -99,11 +99,12 @@ class DubboNamespaceHandlerTest {
|
|||
private void testProviderXml(ApplicationContext context) {
|
||||
|
||||
String appName = "demo-provider";
|
||||
String configId = ApplicationConfig.class.getName() + "#" + appName + "#0";
|
||||
Map<String, ApplicationConfig> applicationConfigMap = context.getBeansOfType(ApplicationConfig.class);
|
||||
ApplicationConfig providerAppConfig = context.getBean(appName, ApplicationConfig.class);
|
||||
ApplicationConfig providerAppConfig = context.getBean(configId, ApplicationConfig.class);
|
||||
assertNotNull(providerAppConfig);
|
||||
assertEquals(appName, providerAppConfig.getName());
|
||||
assertEquals(appName, providerAppConfig.getId());
|
||||
// assertEquals(configId, providerAppConfig.getId());
|
||||
|
||||
ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
|
||||
assertThat(protocolConfig, not(nullValue()));
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
http://dubbo.apache.org/schema/dubbo
|
||||
http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
|
||||
|
||||
<dubbo:application name="dubbo-consumer-2.7.x">
|
||||
<dubbo:application id="dubbo-consumer-2.7.x" name="dubbo-consumer-2.7.x">
|
||||
<dubbo:parameter key="qos.enable" value="false"/>
|
||||
</dubbo:application>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
|
|
|||
Loading…
Reference in New Issue