Search in sources :

Example 1 with ApplicationConfig

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())));
    }
}
Also used : Ordered(org.springframework.core.Ordered) Logger(org.slf4j.Logger) ENVIRONMENT_BEAN_NAME(org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) LoggerFactory(org.slf4j.LoggerFactory) BeanFactoryUtils(org.springframework.beans.factory.BeanFactoryUtils) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) ApplicationListener(org.springframework.context.ApplicationListener) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Objects(java.util.Objects) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Stream(java.util.stream.Stream) Environment(org.springframework.core.env.Environment) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) EnableDubboConfig(org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig) BeanFactoryUtils.beanNamesForTypeIncludingAncestors(org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) Environment(org.springframework.core.env.Environment)

Example 2 with ApplicationConfig

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());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.Test)

Example 3 with ApplicationConfig

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());
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) Test(org.junit.Test)

Example 4 with ApplicationConfig

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());
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) Test(org.junit.Test)

Example 5 with ApplicationConfig

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);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)75 RegistryConfig (org.apache.dubbo.config.RegistryConfig)42 Test (org.junit.jupiter.api.Test)32 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)27 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)19 ServiceConfig (org.apache.dubbo.config.ServiceConfig)18 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 URL (org.apache.dubbo.common.URL)9 GenericService (org.apache.dubbo.rpc.service.GenericService)8 Test (org.junit.Test)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 MonitorConfig (org.apache.dubbo.config.MonitorConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AbstractInterfaceConfigTest (org.apache.dubbo.config.AbstractInterfaceConfigTest)4 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)4 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)3 ModuleConfig (org.apache.dubbo.config.ModuleConfig)3 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)3