Search in sources :

Example 26 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.

the class ReferenceConfigCacheTest method buildMockReferenceConfig.

private MockReferenceConfig buildMockReferenceConfig(String service, String group, String version) {
    MockReferenceConfig config = new MockReferenceConfig();
    config.setApplication(new ApplicationConfig("cache"));
    config.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
    config.setCheck(false);
    config.setInterface(service);
    config.setGroup(group);
    config.setVersion(version);
    return config;
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig)

Example 27 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.

the class ServiceOrientedRegistryTest method init.

@BeforeEach
public void init() {
    registry = ServiceDiscoveryRegistry.create(registryURL);
    metadataService = WritableMetadataService.getDefaultExtension();
    notifyListener = new MyNotifyListener();
    ApplicationModel.getConfigManager().setApplication(new ApplicationConfig("Test"));
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.

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 29 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.

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 30 with ApplicationConfig

use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.

the class ServiceAnnotationTestConfiguration2 method applicationConfig.

/**
 * Current application configuration, to replace XML config:
 * <prev>
 * &lt;dubbo:application name="dubbo-demo-application"/&gt;
 * </prev>
 *
 * @return {@link ApplicationConfig} Bean
 */
@Bean("dubbo-demo-application")
public ApplicationConfig applicationConfig() {
    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("dubbo-demo-application");
    return applicationConfig;
}
Also used : ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) Bean(org.springframework.context.annotation.Bean)

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