use of org.apache.dubbo.config.ApplicationConfig in project incubator-dubbo-spring-boot-project by apache.
the class DubboConfigBeanDefinitionConflictApplicationListener method resolveUniqueApplicationConfigBean.
/**
* Resolve the unique {@link ApplicationConfig} Bean
* @param registry {@link BeanDefinitionRegistry} instance
* @param beanFactory {@link ConfigurableListableBeanFactory} instance
* @see EnableDubboConfig
*/
private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ListableBeanFactory beanFactory) {
String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length < 2) {
// If the number of ApplicationConfig beans is less than two, return immediately.
return;
}
Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
// Remove ApplicationConfig Beans that are configured by "dubbo.application.*"
Stream.of(beansNames).filter(beansName -> isConfiguredApplicationConfigBeanName(environment, beansName)).forEach(registry::removeBeanDefinition);
beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length > 1) {
throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames).map(registry::getBeanDefinition).collect(Collectors.toList())));
}
}
use of org.apache.dubbo.config.ApplicationConfig in project incubator-dubbo-spring-boot-project by apache.
the class RelaxedDubboConfigBinderTest method testBinder.
@Test
public void testBinder() {
ApplicationConfig applicationConfig = new ApplicationConfig();
Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application");
dubboConfigBinder.bind(properties, true, true, applicationConfig);
Assert.assertEquals("hello", applicationConfig.getName());
Assert.assertEquals("world", applicationConfig.getOwner());
RegistryConfig registryConfig = new RegistryConfig();
properties = getSubProperties(environment.getPropertySources(), "dubbo.registry");
dubboConfigBinder.bind(properties, true, true, registryConfig);
Assert.assertEquals("10.20.153.17", registryConfig.getAddress());
ProtocolConfig protocolConfig = new ProtocolConfig();
properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol");
dubboConfigBinder.bind(properties, true, true, protocolConfig);
Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());
}
use of org.apache.dubbo.config.ApplicationConfig in project incubator-dubbo-spring-boot-project by apache.
the class DubboConfigBeanDefinitionConflictApplicationListenerTest method testDuplicatedConfigsCase.
@Test
public void testDuplicatedConfigsCase() {
context.register(PropertySourceConfig.class, DubboConfig.class);
context.register(XmlConfig.class);
context.refresh();
Map<String, ApplicationConfig> beansMap = context.getBeansOfType(ApplicationConfig.class);
ApplicationConfig applicationConfig = beansMap.get("dubbo-consumer-2.7.x");
Assert.assertEquals(1, beansMap.size());
Assert.assertEquals("dubbo-consumer-2.7.x", applicationConfig.getName());
}
use of org.apache.dubbo.config.ApplicationConfig in project incubator-dubbo-spring-boot-project by apache.
the class DubboConfigBeanDefinitionConflictApplicationListenerTest method testNormalCase.
@Test
public void testNormalCase() {
System.setProperty("dubbo.application.name", "test-dubbo-application");
context.register(DubboConfig.class);
context.refresh();
ApplicationConfig applicationConfig = context.getBean(ApplicationConfig.class);
Assert.assertEquals("test-dubbo-application", applicationConfig.getName());
}
use of org.apache.dubbo.config.ApplicationConfig in project incubator-dubbo-ops by apache.
the class GenericServiceImpl method init.
@PostConstruct
public void init() {
RegistryConfig registryConfig = buildRegistryConfig(registry);
applicationConfig = new ApplicationConfig();
applicationConfig.setName("dubbo-admin");
applicationConfig.setRegistry(registryConfig);
}
Aggregations