提交 b82e34a5 编写于 作者: 武汉红喜's avatar 武汉红喜

upgrade dubbo to 2.7.2

上级 51a2334d
...@@ -28,7 +28,7 @@ whatsmars-spring-cloud | Spring Cloud 微服务生态 ...@@ -28,7 +28,7 @@ whatsmars-spring-cloud | Spring Cloud 微服务生态
whatsmars-zk | zookeeper remoting 封装 whatsmars-zk | zookeeper remoting 封装
### Rocket Stack ### Rocket Stack
- [x] [*Dubbo*](https://github.com/alibaba/dubbo) - [x] [*Dubbo*](https://github.com/apache/dubbo)
- [x] [*ZooKeeper*](https://github.com/apache/zookeeper) - [x] [*ZooKeeper*](https://github.com/apache/zookeeper)
- [x] [*RocketMQ*](https://github.com/apache/rocketmq) - [x] [*RocketMQ*](https://github.com/apache/rocketmq)
- [x] [*Kafka*](https://github.com/apache/kafka) - [x] [*Kafka*](https://github.com/apache/kafka)
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<commons-lang.version>2.6</commons-lang.version> <commons-lang.version>2.6</commons-lang.version>
<commons-logging.version>1.2</commons-logging.version> <commons-logging.version>1.2</commons-logging.version>
<curator.version>2.12.0</curator.version> <curator.version>2.12.0</curator.version>
<dubbo.version>2.7.0</dubbo.version> <dubbo.version>2.7.2</dubbo.version>
<fastjson.version>1.2.44</fastjson.version> <fastjson.version>1.2.44</fastjson.version>
<guava.version>20.0</guava.version> <guava.version>20.0</guava.version>
<hessian.version>4.0.7</hessian.version> <hessian.version>4.0.7</hessian.version>
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.spring.starter.autoconfigure;
import org.apache.dubbo.common.utils.Assert;
import org.springframework.core.env.PropertyResolver;
import org.springframework.lang.Nullable;
/**
* Delegating {@link PropertyResolver}
*
* @since 2.7.1
*/
class DelegatingPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
DelegatingPropertyResolver(PropertyResolver delegate) {
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
@Nullable
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
@Nullable
public <T> T getProperty(String key, Class<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
}
\ No newline at end of file
...@@ -16,69 +16,59 @@ ...@@ -16,69 +16,59 @@
*/ */
package org.apache.dubbo.spring.starter.autoconfigure; package org.apache.dubbo.spring.starter.autoconfigure;
import org.apache.dubbo.config.AbstractConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment; import org.springframework.core.env.PropertyResolver;
import java.util.Set; import java.util.Set;
import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE; import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
/** /**
* Dubbo Auto {@link Configuration} * Dubbo Auto {@link Configuration}
* *
* @see ApplicationConfig
* @see Service
* @see Reference * @see Reference
* @see DubboComponentScan * @see Service
* @see EnableDubboConfig * @see ServiceAnnotationBeanPostProcessor
* @see EnableDubbo * @see ReferenceAnnotationBeanPostProcessor
* @since 1.0.0 * @since 2.7.0
*/ */
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true)
@Configuration @Configuration
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true, havingValue = "true") @AutoConfigureAfter(DubboRelaxedBindingAutoConfiguration.class)
@ConditionalOnClass(AbstractConfig.class) @EnableConfigurationProperties(DubboConfigurationProperties.class)
public class DubboAutoConfiguration { public class DubboAutoConfiguration {
/** /**
* Creates {@link ServiceAnnotationBeanPostProcessor} Bean * Creates {@link ServiceAnnotationBeanPostProcessor} Bean
* *
* @param environment {@link Environment} Bean * @param propertyResolver {@link PropertyResolver} Bean
* @return {@link ServiceAnnotationBeanPostProcessor} * @return {@link ServiceAnnotationBeanPostProcessor}
*/ */
@ConditionalOnProperty(name = BASE_PACKAGES_PROPERTY_NAME) @ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnClass(ConfigurationPropertySources.class) @ConditionalOnBean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
@Bean @Bean
public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(Environment environment) { public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(
Set<String> packagesToScan = environment.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet()); @Qualifier(BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) PropertyResolver propertyResolver) {
Set<String> packagesToScan = propertyResolver.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet());
return new ServiceAnnotationBeanPostProcessor(packagesToScan); return new ServiceAnnotationBeanPostProcessor(packagesToScan);
} }
@ConditionalOnClass(Binder.class)
@Bean
@Scope(scopeName = SCOPE_PROTOTYPE)
public RelaxedDubboConfigBinder relaxedDubboConfigBinder() {
return new RelaxedDubboConfigBinder();
}
/** /**
* Creates {@link ReferenceAnnotationBeanPostProcessor} Bean if Absent * Creates {@link ReferenceAnnotationBeanPostProcessor} Bean if Absent
* *
...@@ -96,7 +86,7 @@ public class DubboAutoConfiguration { ...@@ -96,7 +86,7 @@ public class DubboAutoConfiguration {
* @see EnableDubboConfig * @see EnableDubboConfig
* @see DubboConfigConfiguration.Single * @see DubboConfigConfiguration.Single
*/ */
@EnableDubboConfig @Import(DubboConfigConfiguration.Single.class)
protected static class SingleDubboConfigConfiguration { protected static class SingleDubboConfigConfiguration {
} }
...@@ -106,8 +96,8 @@ public class DubboAutoConfiguration { ...@@ -106,8 +96,8 @@ public class DubboAutoConfiguration {
* @see EnableDubboConfig * @see EnableDubboConfig
* @see DubboConfigConfiguration.Multiple * @see DubboConfigConfiguration.Multiple
*/ */
@ConditionalOnProperty(name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true") @ConditionalOnProperty(prefix = DUBBO_CONFIG_PREFIX, name = MULTIPLE_CONFIG_PROPERTY_NAME, matchIfMissing = true)
@EnableDubboConfig(multiple = true) @Import(DubboConfigConfiguration.Multiple.class)
protected static class MultipleDubboConfigConfiguration { protected static class MultipleDubboConfigConfiguration {
} }
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.spring.starter.autoconfigure;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.ConfigCenterBean;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.spring.starter.util.DubboUtils.DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE;
import static org.apache.dubbo.spring.starter.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE;
import static org.apache.dubbo.spring.starter.util.DubboUtils.DUBBO_PREFIX;
/**
* Dubbo {@link ConfigurationProperties Config Properties} only used to generate JSON metadata(non-public class)
*
* @since 2.7.1
*/
@ConfigurationProperties(DUBBO_PREFIX)
class DubboConfigurationProperties {
@NestedConfigurationProperty
private Config config = new Config();
@NestedConfigurationProperty
private Scan scan = new Scan();
// Single Config Bindings
@NestedConfigurationProperty
private ApplicationConfig application = new ApplicationConfig();
@NestedConfigurationProperty
private ModuleConfig module = new ModuleConfig();
@NestedConfigurationProperty
private RegistryConfig registry = new RegistryConfig();
@NestedConfigurationProperty
private ProtocolConfig protocol = new ProtocolConfig();
@NestedConfigurationProperty
private MonitorConfig monitor = new MonitorConfig();
@NestedConfigurationProperty
private ProviderConfig provider = new ProviderConfig();
@NestedConfigurationProperty
private ConsumerConfig consumer = new ConsumerConfig();
@NestedConfigurationProperty
private ConfigCenterBean configCenter = new ConfigCenterBean();
@NestedConfigurationProperty
private MetadataReportConfig metadataReport = new MetadataReportConfig();
// Multiple Config Bindings
private Map<String, ModuleConfig> modules = new LinkedHashMap<>();
private Map<String, RegistryConfig> registrys = new LinkedHashMap<>();
private Map<String, ProtocolConfig> protocols = new LinkedHashMap<>();
private Map<String, MonitorConfig> monitors = new LinkedHashMap<>();
private Map<String, ProviderConfig> providers = new LinkedHashMap<>();
private Map<String, ConsumerConfig> consumers = new LinkedHashMap<>();
private Map<String, ConfigCenterBean> configCenters = new LinkedHashMap<>();
private Map<String, MetadataReportConfig> metadataReports = new LinkedHashMap<>();
public Config getConfig() {
return config;
}
public void setConfig(Config config) {
this.config = config;
}
public Scan getScan() {
return scan;
}
public void setScan(Scan scan) {
this.scan = scan;
}
public ApplicationConfig getApplication() {
return application;
}
public void setApplication(ApplicationConfig application) {
this.application = application;
}
public ModuleConfig getModule() {
return module;
}
public void setModule(ModuleConfig module) {
this.module = module;
}
public RegistryConfig getRegistry() {
return registry;
}
public void setRegistry(RegistryConfig registry) {
this.registry = registry;
}
public ProtocolConfig getProtocol() {
return protocol;
}
public void setProtocol(ProtocolConfig protocol) {
this.protocol = protocol;
}
public MonitorConfig getMonitor() {
return monitor;
}
public void setMonitor(MonitorConfig monitor) {
this.monitor = monitor;
}
public ProviderConfig getProvider() {
return provider;
}
public void setProvider(ProviderConfig provider) {
this.provider = provider;
}
public ConsumerConfig getConsumer() {
return consumer;
}
public void setConsumer(ConsumerConfig consumer) {
this.consumer = consumer;
}
public ConfigCenterBean getConfigCenter() {
return configCenter;
}
public void setConfigCenter(ConfigCenterBean configCenter) {
this.configCenter = configCenter;
}
public MetadataReportConfig getMetadataReport() {
return metadataReport;
}
public void setMetadataReport(MetadataReportConfig metadataReport) {
this.metadataReport = metadataReport;
}
public Map<String, ModuleConfig> getModules() {
return modules;
}
public void setModules(Map<String, ModuleConfig> modules) {
this.modules = modules;
}
public Map<String, RegistryConfig> getRegistrys() {
return registrys;
}
public void setRegistrys(Map<String, RegistryConfig> registrys) {
this.registrys = registrys;
}
public Map<String, ProtocolConfig> getProtocols() {
return protocols;
}
public void setProtocols(Map<String, ProtocolConfig> protocols) {
this.protocols = protocols;
}
public Map<String, MonitorConfig> getMonitors() {
return monitors;
}
public void setMonitors(Map<String, MonitorConfig> monitors) {
this.monitors = monitors;
}
public Map<String, ProviderConfig> getProviders() {
return providers;
}
public void setProviders(Map<String, ProviderConfig> providers) {
this.providers = providers;
}
public Map<String, ConsumerConfig> getConsumers() {
return consumers;
}
public void setConsumers(Map<String, ConsumerConfig> consumers) {
this.consumers = consumers;
}
public Map<String, ConfigCenterBean> getConfigCenters() {
return configCenters;
}
public void setConfigCenters(Map<String, ConfigCenterBean> configCenters) {
this.configCenters = configCenters;
}
public Map<String, MetadataReportConfig> getMetadataReports() {
return metadataReports;
}
public void setMetadataReports(Map<String, MetadataReportConfig> metadataReports) {
this.metadataReports = metadataReports;
}
static class Config {
/**
* Indicates multiple properties binding from externalized configuration or not.
*/
private boolean multiple = DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE;
/**
* The property name of override Dubbo config
*/
private boolean override = DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE;
public boolean isOverride() {
return override;
}
public void setOverride(boolean override) {
this.override = override;
}
public boolean isMultiple() {
return multiple;
}
public void setMultiple(boolean multiple) {
this.multiple = multiple;
}
}
static class Scan {
/**
* The basePackages to scan , the multiple-value is delimited by comma
*
* @see EnableDubbo#scanBasePackages()
*/
private Set<String> basePackages = new LinkedHashSet<>();
public Set<String> getBasePackages() {
return basePackages;
}
public void setBasePackages(Set<String> basePackages) {
this.basePackages = basePackages;
}
}
}
\ No newline at end of file
package org.apache.dubbo.spring.starter.autoconfigure;
import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;
import org.apache.dubbo.config.spring.util.PropertySourcesUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertyResolver;
import java.util.Map;
import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;
/**
* Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 2.0
*
* @since 2.7.0
*/
@Configuration
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true)
@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
public class DubboRelaxedBindingAutoConfiguration {
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
Map<String, Object> dubboScanProperties = PropertySourcesUtils.getSubProperties(environment, DUBBO_SCAN_PREFIX);
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
}
};
ConfigurationPropertySources.attach(propertyResolver);
return new DelegatingPropertyResolver(propertyResolver);
}
@ConditionalOnMissingBean(name = RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME, value = DubboConfigBinder.class)
@Bean(RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME)
@Scope(scopeName = SCOPE_PROTOTYPE)
public DubboConfigBinder relaxedDubboConfigBinder() {
return new RelaxedDubboConfigBinder();
}
}
\ No newline at end of file
...@@ -35,9 +35,9 @@ import static org.springframework.boot.context.properties.source.ConfigurationPr ...@@ -35,9 +35,9 @@ import static org.springframework.boot.context.properties.source.ConfigurationPr
* Spring Boot Relaxed {@link DubboConfigBinder} implementation * Spring Boot Relaxed {@link DubboConfigBinder} implementation
* see org.springframework.boot.context.properties.ConfigurationPropertiesBinder * see org.springframework.boot.context.properties.ConfigurationPropertiesBinder
* *
* @since 0.1.1 * @since 2.7.0
*/ */
public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder { class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {
@Override @Override
public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) { public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) {
...@@ -71,4 +71,4 @@ public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder { ...@@ -71,4 +71,4 @@ public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {
} }
return handler; return handler;
} }
} }
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.spring.starter.beans.factory.config;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors;
import static org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME;
/**
* Dubbo Config {@link BeanDefinition Bean Definition} {@link BeanDefinitionRegistryPostProcessor processor}
* to resolve conflict
*
* @see BeanDefinition
* @see BeanDefinitionRegistryPostProcessor
* @since 2.7.1
*/
public class DubboConfigBeanDefinitionConflictProcessor implements BeanDefinitionRegistryPostProcessor, Ordered {
private final Logger logger = LoggerFactory.getLogger(getClass());
private BeanDefinitionRegistry registry;
private Environment environment;
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
this.registry = registry;
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
resolveUniqueApplicationConfigBean(registry, beanFactory);
}
/**
* Resolve the unique {@link ApplicationConfig} Bean
*
* @param registry {@link BeanDefinitionRegistry} instance
* @param beanFactory {@link ConfigurableListableBeanFactory} instance
* @see EnableDubboConfig
*/
private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry,
ConfigurableListableBeanFactory beanFactory) {
this.environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length < 2) { // If the number of ApplicationConfig beans is less than two, return immediately.
return;
}
// Remove ApplicationConfig Beans that are configured by "dubbo.application.*"
Stream.of(beansNames)
.filter(this::isConfiguredApplicationConfigBeanName)
.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()))
);
}
}
private boolean isConfiguredApplicationConfigBeanName(String beanName) {
boolean removed = BeanFactoryUtils.isGeneratedBeanName(beanName)
// Dubbo ApplicationConfig id as bean name
|| Objects.equals(beanName, environment.getProperty("dubbo.application.id"));
if (removed) {
if (logger.isWarnEnabled()) {
logger.warn("The {} bean [ name : {} ] has been removed!", ApplicationConfig.class.getSimpleName(), beanName);
}
}
return removed;
}
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.spring.starter.context;
import org.apache.dubbo.spring.starter.beans.factory.config.DubboConfigBeanDefinitionConflictProcessor;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
/**
* Dubbo {@link ApplicationContextInitializer} implementation
*
* @see ApplicationContextInitializer
* @since 2.7.1
*/
public class DubboApplicationContextInitializer implements ApplicationContextInitializer, Ordered {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
overrideBeanDefinitions(applicationContext);
}
private void overrideBeanDefinitions(ConfigurableApplicationContext applicationContext) {
applicationContext.addBeanFactoryPostProcessor(new DubboConfigBeanDefinitionConflictProcessor());
}
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
\ No newline at end of file
...@@ -19,12 +19,13 @@ package org.apache.dubbo.spring.starter.context.event; ...@@ -19,12 +19,13 @@ package org.apache.dubbo.spring.starter.context.event;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.SmartApplicationListener; import org.springframework.context.event.SmartApplicationListener;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
...@@ -37,10 +38,15 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -37,10 +38,15 @@ import java.util.concurrent.locks.ReentrantLock;
/** /**
* Awaiting Non-Web Spring Boot {@link ApplicationListener} * Awaiting Non-Web Spring Boot {@link ApplicationListener}
* *
* @since 0.1.1 * @since 2.7.0
*/ */
public class AwaitingNonWebApplicationListener implements SmartApplicationListener { public class AwaitingNonWebApplicationListener implements SmartApplicationListener {
private static final String[] WEB_APPLICATION_CONTEXT_CLASSES = new String[]{
"org.springframework.web.context.WebApplicationContext",
"org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext"
};
private static final Logger logger = LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class); private static final Logger logger = LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class);
private static final Class<? extends ApplicationEvent>[] SUPPORTED_APPLICATION_EVENTS = private static final Class<? extends ApplicationEvent>[] SUPPORTED_APPLICATION_EVENTS =
...@@ -54,6 +60,14 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen ...@@ -54,6 +60,14 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen
private final ExecutorService executorService = Executors.newSingleThreadExecutor(); private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private static <T> T[] of(T... values) {
return values;
}
static AtomicBoolean getAwaited() {
return awaited;
}
@Override @Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) { public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType); return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType);
...@@ -64,10 +78,6 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen ...@@ -64,10 +78,6 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen
return true; return true;
} }
private static <T> T[] of(T... values) {
return values;
}
@Override @Override
public void onApplicationEvent(ApplicationEvent event) { public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationReadyEvent) { if (event instanceof ApplicationReadyEvent) {
...@@ -86,12 +96,30 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen ...@@ -86,12 +96,30 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen
final SpringApplication springApplication = event.getSpringApplication(); final SpringApplication springApplication = event.getSpringApplication();
if (!WebApplicationType.NONE.equals(springApplication.getWebApplicationType())) { if (isWebApplication(event.getApplicationContext(), springApplication.getClassLoader())) {
return; return;
} }
await(); await();
}
private static boolean isWebApplication(ApplicationContext applicationContext, ClassLoader classLoader) {
boolean webApplication = false;
for (String contextClass : WEB_APPLICATION_CONTEXT_CLASSES) {
if (isAssignable(contextClass, applicationContext.getClass(), classLoader)) {
webApplication = true;
break;
}
}
return webApplication;
}
private static boolean isAssignable(String target, Class<?> type, ClassLoader classLoader) {
try {
return ClassUtils.resolveClassName(target, classLoader).isAssignableFrom(type);
} catch (Throwable ex) {
return false;
}
} }
protected void onContextClosedEvent(ContextClosedEvent event) { protected void onContextClosedEvent(ContextClosedEvent event) {
...@@ -146,8 +174,4 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen ...@@ -146,8 +174,4 @@ public class AwaitingNonWebApplicationListener implements SmartApplicationListen
lock.unlock(); lock.unlock();
} }
} }
static AtomicBoolean getAwaited() {
return awaited;
}
} }
...@@ -28,7 +28,9 @@ import org.springframework.core.env.Environment; ...@@ -28,7 +28,9 @@ import org.springframework.core.env.Environment;
import java.util.SortedMap; import java.util.SortedMap;
import static org.apache.dubbo.spring.starter.util.DubboUtils.*; import static org.apache.dubbo.spring.starter.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE;
import static org.apache.dubbo.spring.starter.util.DubboUtils.OVERRIDE_CONFIG_FULL_PROPERTY_NAME;
import static org.apache.dubbo.spring.starter.util.DubboUtils.filterDubboProperties;
/** /**
* {@link ApplicationListener} to override the dubbo properties from {@link Environment}into * {@link ApplicationListener} to override the dubbo properties from {@link Environment}into
...@@ -37,7 +39,7 @@ import static org.apache.dubbo.spring.starter.util.DubboUtils.*; ...@@ -37,7 +39,7 @@ import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
* <p> * <p>
* *
* @see ConfigUtils * @see ConfigUtils
* @since 1.0.0 * @since 2.7.0
*/ */
@Order // LOWEST_PRECEDENCE Make sure last execution @Order // LOWEST_PRECEDENCE Make sure last execution
public class OverrideDubboConfigApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { public class OverrideDubboConfigApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
...@@ -53,7 +55,7 @@ public class OverrideDubboConfigApplicationListener implements ApplicationListen ...@@ -53,7 +55,7 @@ public class OverrideDubboConfigApplicationListener implements ApplicationListen
ConfigurableEnvironment environment = event.getEnvironment(); ConfigurableEnvironment environment = event.getEnvironment();
boolean override = environment.getProperty(OVERRIDE_CONFIG_PROPERTY_NAME, boolean.class, boolean override = environment.getProperty(OVERRIDE_CONFIG_FULL_PROPERTY_NAME, boolean.class,
DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE);
if (override) { if (override) {
...@@ -63,19 +65,12 @@ public class OverrideDubboConfigApplicationListener implements ApplicationListen ...@@ -63,19 +65,12 @@ public class OverrideDubboConfigApplicationListener implements ApplicationListen
ConfigUtils.getProperties().putAll(dubboProperties); ConfigUtils.getProperties().putAll(dubboProperties);
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Dubbo Config was overridden by externalized configuration {}", dubboProperties); logger.info("Dubbo Config was overridden by externalized configuration {}", dubboProperties);
} }
} else { } else {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Disable override Dubbo Config caused by property {} = {}", OVERRIDE_CONFIG_FULL_PROPERTY_NAME, override);
logger.info("Disable override Dubbo Config caused by property {} = {}", OVERRIDE_CONFIG_PROPERTY_NAME, override);
} }
} }
} }
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
package org.apache.dubbo.spring.starter.context.event; package org.apache.dubbo.spring.starter.context.event;
import org.apache.dubbo.common.Version; import org.apache.dubbo.common.Version;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -32,9 +33,9 @@ import static org.apache.dubbo.spring.starter.util.DubboUtils.*; ...@@ -32,9 +33,9 @@ import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
* Dubbo Welcome Logo {@link ApplicationListener} * Dubbo Welcome Logo {@link ApplicationListener}
* *
* @see ApplicationListener * @see ApplicationListener
* @since 1.0.0 * @since 2.7.0
*/ */
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1) @Order(Ordered.HIGHEST_PRECEDENCE + 20 + 1) // After LoggingApplicationListener#DEFAULT_ORDER
public class WelcomeLogoApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> { public class WelcomeLogoApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static AtomicBoolean processed = new AtomicBoolean(false); private static AtomicBoolean processed = new AtomicBoolean(false);
...@@ -72,7 +73,7 @@ public class WelcomeLogoApplicationListener implements ApplicationListener<Appli ...@@ -72,7 +73,7 @@ public class WelcomeLogoApplicationListener implements ApplicationListener<Appli
bannerTextBuilder bannerTextBuilder
.append(LINE_SEPARATOR) .append(LINE_SEPARATOR)
.append(LINE_SEPARATOR) .append(LINE_SEPARATOR)
.append(" :: Dubbo Spring Boot (v").append(Version.getVersion(getClass(), "1.0.0")).append(") : ") .append(" :: Dubbo Spring Boot (v").append(Version.getVersion(getClass(), Version.getVersion())).append(") : ")
.append(DUBBO_SPRING_BOOT_GITHUB_URL) .append(DUBBO_SPRING_BOOT_GITHUB_URL)
.append(LINE_SEPARATOR) .append(LINE_SEPARATOR)
.append(" :: Dubbo (v").append(Version.getVersion()).append(") : ") .append(" :: Dubbo (v").append(Version.getVersion()).append(") : ")
......
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
*/ */
package org.apache.dubbo.spring.starter.env; package org.apache.dubbo.spring.starter.env;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.ContextIdApplicationContextInitializer;
import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.env.*; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -32,6 +32,8 @@ import java.util.HashMap; ...@@ -32,6 +32,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import static org.apache.dubbo.spring.starter.util.DubboUtils.*;
/** /**
* The lowest precedence {@link EnvironmentPostProcessor} processes * The lowest precedence {@link EnvironmentPostProcessor} processes
* {@link SpringApplication#setDefaultProperties(Properties) Spring Boot default properties} for Dubbo * {@link SpringApplication#setDefaultProperties(Properties) Spring Boot default properties} for Dubbo
...@@ -42,32 +44,13 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme ...@@ -42,32 +44,13 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme
/** /**
* The name of default {@link PropertySource} defined in SpringApplication#configurePropertySources method. * The name of default {@link PropertySource} defined in SpringApplication#configurePropertySources method.
*/ */
private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; public static final String PROPERTY_SOURCE_NAME = "defaultProperties";
/**
* The property name of Spring Application
*
* @see ContextIdApplicationContextInitializer
*/
private static final String SPRING_APPLICATION_NAME_PROPERTY = "spring.application.name";
/**
* The property name of {@link ApplicationConfig}
*
* @see EnableDubboConfig
* @see EnableDubboConfigBinding
*/
private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name";
/** /**
* The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()} * The property name of "spring.main.allow-bean-definition-overriding".
* Please refer to: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#bean-overriding
*/ */
private static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple"; public static final String ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY = "spring.main.allow-bean-definition-overriding";
/**
* The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable}
*/
private static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable";
@Override @Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
...@@ -88,6 +71,7 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme ...@@ -88,6 +71,7 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme
setDubboApplicationNameProperty(environment, defaultProperties); setDubboApplicationNameProperty(environment, defaultProperties);
setDubboConfigMultipleProperty(defaultProperties); setDubboConfigMultipleProperty(defaultProperties);
setDubboApplicationQosEnableProperty(defaultProperties); setDubboApplicationQosEnableProperty(defaultProperties);
setAllowBeanDefinitionOverriding(defaultProperties);
return defaultProperties; return defaultProperties;
} }
...@@ -107,6 +91,18 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme ...@@ -107,6 +91,18 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme
defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString()); defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString());
} }
/**
* Set {@link #ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY "spring.main.allow-bean-definition-overriding"} to be
* <code>true</code> as default.
*
* @param defaultProperties the default {@link Properties properties}
* @see #ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY
* @since 2.7.1
*/
private void setAllowBeanDefinitionOverriding(Map<String, Object> defaultProperties) {
defaultProperties.put(ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY, Boolean.TRUE.toString());
}
/** /**
* Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)
* *
......
...@@ -16,7 +16,15 @@ ...@@ -16,7 +16,15 @@
*/ */
package org.apache.dubbo.spring.starter.util; package org.apache.dubbo.spring.starter.util;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding;
import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;
import org.springframework.boot.context.ContextIdApplicationContextInitializer;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertyResolver;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
...@@ -26,7 +34,7 @@ import java.util.TreeMap; ...@@ -26,7 +34,7 @@ import java.util.TreeMap;
/** /**
* The utilities class for Dubbo * The utilities class for Dubbo
* *
* @since 1.0.0 * @since 2.7.0
*/ */
public abstract class DubboUtils { public abstract class DubboUtils {
...@@ -49,38 +57,38 @@ public abstract class DubboUtils { ...@@ -49,38 +57,38 @@ public abstract class DubboUtils {
/** /**
* The prefix of property name for Dubbo scan * The prefix of property name for Dubbo scan
*/ */
public static final String DUBBO_SCAN_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "scan"; public static final String DUBBO_SCAN_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "scan" + PROPERTY_NAME_SEPARATOR;
/** /**
* The prefix of property name for Dubbo Config.ØØ * The prefix of property name for Dubbo Config
*/ */
public static final String DUBBO_CONFIG_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "config"; public static final String DUBBO_CONFIG_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "config" + PROPERTY_NAME_SEPARATOR;
/** /**
* The property name of base packages to scan * The property name of base packages to scan
* <p> * <p>
* The default value is empty set. * The default value is empty set.
*/ */
public static final String BASE_PACKAGES_PROPERTY_NAME = DUBBO_SCAN_PREFIX + PROPERTY_NAME_SEPARATOR + "base-packages"; public static final String BASE_PACKAGES_PROPERTY_NAME = "base-packages";
/** /**
* The property name of multiple properties binding from externalized configuration * The property name of multiple properties binding from externalized configuration
* <p> * <p>
* The default value is {@link #DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE} * The default value is {@link #DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE}
*/ */
public static final String MULTIPLE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "multiple"; public static final String MULTIPLE_CONFIG_PROPERTY_NAME = "multiple";
/** /**
* The default value of multiple properties binding from externalized configuration * The default value of multiple properties binding from externalized configuration
*/ */
public static final boolean DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE = false; public static final boolean DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE = true;
/** /**
* The property name of override Dubbo config * The property name of override Dubbo config
* <p> * <p>
* The default value is {@link #DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE} * The default value is {@link #DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE}
*/ */
public static final String OVERRIDE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "override"; public static final String OVERRIDE_CONFIG_FULL_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + "override";
/** /**
* The default property value of override Dubbo config * The default property value of override Dubbo config
...@@ -91,28 +99,79 @@ public abstract class DubboUtils { ...@@ -91,28 +99,79 @@ public abstract class DubboUtils {
/** /**
* The github URL of Dubbo Spring Boot * The github URL of Dubbo Spring Boot
*/ */
public static final String DUBBO_SPRING_BOOT_GITHUB_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project"; public static final String DUBBO_SPRING_BOOT_GITHUB_URL = "https://github.com/apache/dubbo-spring-boot-project";
/** /**
* The git URL of Dubbo Spring Boot * The git URL of Dubbo Spring Boot
*/ */
public static final String DUBBO_SPRING_BOOT_GIT_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project.git"; public static final String DUBBO_SPRING_BOOT_GIT_URL = "https://github.com/apache/dubbo-spring-boot-project.git";
/** /**
* The issues of Dubbo Spring Boot * The issues of Dubbo Spring Boot
*/ */
public static final String DUBBO_SPRING_BOOT_ISSUES_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project/issues"; public static final String DUBBO_SPRING_BOOT_ISSUES_URL = "https://github.com/apache/dubbo-spring-boot-project/issues";
/** /**
* The github URL of Dubbo * The github URL of Dubbo
*/ */
public static final String DUBBO_GITHUB_URL = "https://github.com/apache/incubator-dubbo"; public static final String DUBBO_GITHUB_URL = "https://github.com/apache/dubbo";
/** /**
* The google group URL of Dubbo * The google group URL of Dubbo
*/ */
public static final String DUBBO_MAILING_LIST = "dev@dubbo.apache.org"; public static final String DUBBO_MAILING_LIST = "dev@dubbo.apache.org";
/**
* The bean name of Relaxed-binding {@link DubboConfigBinder}
*/
public static final String RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME = "relaxedDubboConfigBinder";
/**
* The bean name of {@link PropertyResolver} for {@link ServiceAnnotationBeanPostProcessor}'s base-packages
*/
public static final String BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME = "dubboScanBasePackagesPropertyResolver";
/**
* The property name of Spring Application
*
* @see ContextIdApplicationContextInitializer
* @since 2.7.1
*/
public static final String SPRING_APPLICATION_NAME_PROPERTY = "spring.application.name";
/**
* The property id of {@link ApplicationConfig} Bean
*
* @see EnableDubboConfig
* @see EnableDubboConfigBinding
* @since 2.7.1
*/
public static final String DUBBO_APPLICATION_ID_PROPERTY = "dubbo.application.id";
/**
* The property name of {@link ApplicationConfig}
*
* @see EnableDubboConfig
* @see EnableDubboConfigBinding
* @since 2.7.1
*/
public static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name";
/**
* The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable}
*
* @since 2.7.1
*/
public static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable";
/**
* The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()}
*
* @since 2.7.1
*/
public static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple";
/** /**
* Filters Dubbo Properties from {@link ConfigurableEnvironment} * Filters Dubbo Properties from {@link ConfigurableEnvironment}
* *
......
...@@ -27,7 +27,7 @@ import java.util.Map; ...@@ -27,7 +27,7 @@ import java.util.Map;
* The utilities class for {@link Environment} * The utilities class for {@link Environment}
* *
* @see Environment * @see Environment
* @since 1.0.0 * @since 2.7.0
*/ */
public abstract class EnvironmentUtils { public abstract class EnvironmentUtils {
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.dubbo.spring.starter.autoconfigure.DubboRelaxedBindingAutoConfiguration,\
org.apache.dubbo.spring.starter.autoconfigure.DubboAutoConfiguration org.apache.dubbo.spring.starter.autoconfigure.DubboAutoConfiguration
...@@ -8,4 +9,7 @@ org.apache.dubbo.spring.starter.context.event.WelcomeLogoApplicationListener,\ ...@@ -8,4 +9,7 @@ org.apache.dubbo.spring.starter.context.event.WelcomeLogoApplicationListener,\
org.apache.dubbo.spring.starter.context.event.AwaitingNonWebApplicationListener org.apache.dubbo.spring.starter.context.event.AwaitingNonWebApplicationListener
org.springframework.boot.env.EnvironmentPostProcessor=\ org.springframework.boot.env.EnvironmentPostProcessor=\
org.apache.dubbo.spring.starter.env.DubboDefaultPropertiesEnvironmentPostProcessor org.apache.dubbo.spring.starter.env.DubboDefaultPropertiesEnvironmentPostProcessor
\ No newline at end of file
org.springframework.context.ApplicationContextInitializer=\
org.apache.dubbo.spring.starter.context.DubboApplicationContextInitializer
\ No newline at end of file
package org.hongxi.whatsmars.dubbo.demo.consumer; package org.hongxi.whatsmars.dubbo.demo.consumer;
import org.hongxi.whatsmars.dubbo.demo.consumer.rpc.DemoRpc;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
/** /**
* Created by javahongxi on 2017/12/4. * Created by javahongxi on 2017/12/4.
...@@ -11,9 +9,6 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -11,9 +9,6 @@ import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication @SpringBootApplication
public class ConsumerApplication { public class ConsumerApplication {
public static void main(String[] args) { public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(ConsumerApplication.class, args); SpringApplication.run(ConsumerApplication.class, args);
// DemoRpc demoRpc = context.getBean(DemoRpc.class);
// System.out.println(demoRpc.sayHello("Lily"));
// System.out.println(demoRpc.sayHello2("Lily"));
} }
} }
...@@ -15,10 +15,10 @@ public class DemoRpc { ...@@ -15,10 +15,10 @@ public class DemoRpc {
/** /**
* 当不指定registry时,Reference会从所有含有该service的registry里选择一个registry * 当不指定registry时,Reference会从所有含有该service的registry里选择一个registry
*/ */
@Reference(registry = "defaultRegistry", check = false) @Reference(registry = "defaultRegistry")
private DemoService demoService; private DemoService demoService;
@Reference(registry = "otherRegistry", check = false) @Reference(registry = "otherRegistry")
private OtherService otherService; private OtherService otherService;
public String sayHello(String name) { public String sayHello(String name) {
......
...@@ -22,19 +22,15 @@ public class AsyncConsumer2 { ...@@ -22,19 +22,15 @@ public class AsyncConsumer2 {
final DemoService demoService = (DemoService) context.getBean("demoService"); final DemoService demoService = (DemoService) context.getBean("demoService");
Future<String> f = RpcContext.getContext().asyncCall(new Callable<String>() { Future<String> f = RpcContext.getContext().asyncCall(() -> {
public String call() throws Exception { return demoService.sayHello("async call request");
return demoService.sayHello("async call request");
}
}); });
System.out.println("async call ret :" + f.get()); System.out.println("async call ret :" + f.get());
RpcContext.getContext().asyncCall(new Runnable() { RpcContext.getContext().asyncCall(() -> {
public void run() { demoService.sayHello("oneway call request1");
demoService.sayHello("oneway call request1"); demoService.sayHello("oneway call request2");
demoService.sayHello("oneway call request2");
}
}); });
System.in.read(); System.in.read();
......
...@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -8,7 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/ */
@SpringBootApplication @SpringBootApplication
public class ProviderApplication { public class ProviderApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) {
SpringApplication.run(ProviderApplication.class, args); SpringApplication.run(ProviderApplication.class, args);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册