This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new cdce2b2 [DUBBO-3778]: Annotation mode cannot set service parameters
in 2.7.0 (#4060)
cdce2b2 is described below
commit cdce2b278364c6391a07e35bca8dd5750529a63e
Author: Ian Luo <[email protected]>
AuthorDate: Wed May 15 14:35:25 2019 +0800
[DUBBO-3778]: Annotation mode cannot set service parameters in 2.7.0 (#4060)
---
...mpatibleServiceAnnotationBeanPostProcessor.java | 27 ++++++++++++++++++----
.../ServiceAnnotationBeanPostProcessor.java | 25 ++++++++++++++++++--
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git
a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java
b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java
index b71adfd..3d0370c 100644
---
a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java
+++
b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java
@@ -18,11 +18,11 @@ package
org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.config.spring.ServiceBean;
import
org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
import com.alibaba.dubbo.config.annotation.Service;
-
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanClassLoaderAware;
@@ -54,8 +54,10 @@ import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.config.spring.util.ObjectUtils.of;
@@ -389,7 +391,8 @@ public class CompatibleServiceAnnotationBeanPostProcessor
implements BeanDefinit
MutablePropertyValues propertyValues =
beanDefinition.getPropertyValues();
- String[] ignoreAttributeNames = of("provider", "monitor",
"application", "module", "registry", "protocol", "interface");
+ String[] ignoreAttributeNames = of("provider", "monitor",
"application", "module", "registry", "protocol",
+ "interface", "parameters");
propertyValues.addPropertyValues(new
AnnotationPropertyValuesAdapter(service, environment, ignoreAttributeNames));
@@ -397,6 +400,8 @@ public class CompatibleServiceAnnotationBeanPostProcessor
implements BeanDefinit
addPropertyReference(builder, "ref", annotatedServiceBeanName);
// Set interface
builder.addPropertyValue("interface", interfaceClass.getName());
+ // Convert parameters into map
+ builder.addPropertyValue("parameters",
convertParameters(service.parameters()));
/**
* Add {@link org.apache.dubbo.config.ProviderConfig} Bean reference
@@ -482,6 +487,21 @@ public class CompatibleServiceAnnotationBeanPostProcessor
implements BeanDefinit
builder.addPropertyReference(propertyName, resolvedBeanName);
}
+ private Map<String, String> convertParameters(String[] parameters) {
+ if (ArrayUtils.isEmpty(parameters)) {
+ return null;
+ }
+
+ if (parameters.length % 2 != 0) {
+ throw new IllegalArgumentException("parameter attribute must be
paired with key followed by value");
+ }
+
+ Map<String, String> map = new HashMap<>();
+ for (int i = 0; i < parameters.length; i += 2) {
+ map.put(parameters[i], parameters[i + 1]);
+ }
+ return map;
+ }
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
@@ -502,5 +522,4 @@ public class CompatibleServiceAnnotationBeanPostProcessor
implements BeanDefinit
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
-
-}
\ No newline at end of file
+}
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
index 8a07fee..305e372 100644
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
+++
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
@@ -18,6 +18,7 @@ package
org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.spring.ServiceBean;
import
org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
@@ -53,8 +54,10 @@ import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.config.spring.util.ObjectUtils.of;
@@ -372,7 +375,7 @@ public class ServiceAnnotationBeanPostProcessor implements
BeanDefinitionRegistr
MutablePropertyValues propertyValues =
beanDefinition.getPropertyValues();
String[] ignoreAttributeNames = of("provider", "monitor",
"application", "module", "registry", "protocol",
- "interface", "interfaceName");
+ "interface", "interfaceName", "parameters");
propertyValues.addPropertyValues(new
AnnotationPropertyValuesAdapter(service, environment, ignoreAttributeNames));
@@ -380,6 +383,8 @@ public class ServiceAnnotationBeanPostProcessor implements
BeanDefinitionRegistr
addPropertyReference(builder, "ref", annotatedServiceBeanName);
// Set interface
builder.addPropertyValue("interface", interfaceClass.getName());
+ // Convert parameters into map
+ builder.addPropertyValue("parameters",
convertParameters(service.parameters()));
/**
* Add {@link org.apache.dubbo.config.ProviderConfig} Bean reference
@@ -466,6 +471,22 @@ public class ServiceAnnotationBeanPostProcessor implements
BeanDefinitionRegistr
}
+ private Map<String, String> convertParameters(String[] parameters) {
+ if (ArrayUtils.isEmpty(parameters)) {
+ return null;
+ }
+
+ if (parameters.length % 2 != 0) {
+ throw new IllegalArgumentException("parameter attribute must be
paired with key followed by value");
+ }
+
+ Map<String, String> map = new HashMap<>();
+ for (int i = 0; i < parameters.length; i += 2) {
+ map.put(parameters[i], parameters[i + 1]);
+ }
+ return map;
+ }
+
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
@@ -486,4 +507,4 @@ public class ServiceAnnotationBeanPostProcessor implements
BeanDefinitionRegistr
this.classLoader = classLoader;
}
-}
\ No newline at end of file
+}