From ea04e3716bc5dc59d4a3a2e72b8a18e566086963 Mon Sep 17 00:00:00 2001 From: lizhen Date: Thu, 24 Jan 2019 17:40:34 +0800 Subject: [PATCH 1/2] add @Override annotation for override method --- .../apache/dubbo/rpc/cluster/Configurator.java | 1 + .../rpc/cluster/router/AbstractRouter.java | 1 + .../java/com/alibaba/dubbo/rpc/Protocol.java | 4 +++- .../CompatibleReferenceBeanBuilder.java | 5 ++--- .../AnnotationInjectedBeanPostProcessor.java | 18 +++++------------- .../annotation/ReferenceBeanBuilder.java | 2 +- .../curator/CuratorZookeeperTransporter.java | 2 +- .../support/AbstractZookeeperTransporter.java | 1 + .../zkclient/ZkclientZookeeperTransporter.java | 2 +- 9 files changed, 16 insertions(+), 20 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java index 8d5f02c2861..b85a0461312 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Configurator.java @@ -98,6 +98,7 @@ static Optional> toConfigurators(List urls) { * 1. the url with a specific host ip should have higher priority than 0.0.0.0 * 2. if two url has the same host, compare by priority value; */ + @Override default int compareTo(Configurator o) { if (o == null) { return -1; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java index aa47d654519..f826dae570a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java @@ -62,6 +62,7 @@ public void setForce(boolean force) { this.force = force; } + @Override public int getPriority() { return priority; } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java index 57abfb30656..18035416da2 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Protocol.java @@ -22,14 +22,16 @@ @Deprecated public interface Protocol extends org.apache.dubbo.rpc.Protocol { - Exporter export(Invoker invoker) throws RpcException; + Exporter export(Invoker invoker) throws RpcException; Invoker refer(Class aClass, URL url) throws RpcException; + @Override default org.apache.dubbo.rpc.Exporter export(org.apache.dubbo.rpc.Invoker invoker) throws RpcException { return this.export(new Invoker.CompatibleInvoker<>(invoker)); } + @Override default org.apache.dubbo.rpc.Invoker refer(Class aClass, org.apache.dubbo.common.URL url) throws RpcException { return this.refer(aClass, new URL(url)); } diff --git a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java index 1883f791dcf..16013b37e2f 100644 --- a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java +++ b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java @@ -17,7 +17,6 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import com.alibaba.dubbo.config.annotation.Reference; - import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.spring.ReferenceBean; @@ -104,7 +103,7 @@ protected void preConfigureBean(Reference reference, ReferenceBean referenceBean dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true)); dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true)); dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() { - + @Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); @@ -161,7 +160,7 @@ protected void postConfigureBean(Reference annotation, ReferenceBean bean) throw } public static CompatibleReferenceBeanBuilder create(Reference annotation, ClassLoader classLoader, - ApplicationContext applicationContext) { + ApplicationContext applicationContext) { return new CompatibleReferenceBeanBuilder(annotation, classLoader, applicationContext); } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java index 1dc147f0dda..1e68815e225 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java @@ -21,11 +21,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.*; import org.springframework.beans.factory.annotation.InjectionMetadata; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -46,13 +42,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -64,7 +54,7 @@ /** * Abstract generic {@link BeanPostProcessor} implementation for customized annotation that annotated injected-object. - * + *

* The source code is cloned from https://github.com/alibaba/spring-context-support/blob/1.0.2/src/main/java/com/alibaba/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java * * @since 2.6.6 @@ -113,6 +103,7 @@ public final Class getAnnotationType() { return annotationType; } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory, "AnnotationInjectedBeanPostProcessor requires a ConfigurableListableBeanFactory"); @@ -293,6 +284,7 @@ public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } + @Override public void setEnvironment(Environment environment) { this.environment = environment; } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java index d415bf76efe..aff3ed2a5d0 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java @@ -102,7 +102,7 @@ protected void preConfigureBean(Reference reference, ReferenceBean referenceBean dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true)); dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true)); dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() { - + @Override public void setAsText(String text) throws java.lang.IllegalArgumentException { // Trim all whitespace String content = StringUtils.trimAllWhitespace(text); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java index b6a6c3ec9f9..21a2e095422 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java @@ -21,7 +21,7 @@ import org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter; public class CuratorZookeeperTransporter extends AbstractZookeeperTransporter { - + @Override public ZookeeperClient createZookeeperClient(URL url) { return new CuratorZookeeperClient(url); } diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java index 5b58dc7b8c3..72c702a1df3 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java @@ -47,6 +47,7 @@ public abstract class AbstractZookeeperTransporter implements ZookeeperTransport * @param url * @return */ + @Override public ZookeeperClient connect(URL url) { ZookeeperClient zookeeperClient; List addressList = getURLBackupAddress(url); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporter.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporter.java index eef25afb3f0..0ad86ff7850 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporter.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperTransporter.java @@ -21,7 +21,7 @@ import org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter; public class ZkclientZookeeperTransporter extends AbstractZookeeperTransporter { - + @Override public ZookeeperClient createZookeeperClient(URL url) { return new ZkclientZookeeperClient(url); } From 69555479be0ef9e7ef1a4241a5d4b2a881087512 Mon Sep 17 00:00:00 2001 From: lizhen Date: Thu, 24 Jan 2019 17:53:03 +0800 Subject: [PATCH 2/2] remove import * --- .../AnnotationInjectedBeanPostProcessor.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java index 1e68815e225..30592a1a7cb 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java @@ -21,7 +21,11 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; -import org.springframework.beans.factory.*; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.InjectionMetadata; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -42,7 +46,13 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -54,7 +64,7 @@ /** * Abstract generic {@link BeanPostProcessor} implementation for customized annotation that annotated injected-object. - *

+ * * The source code is cloned from https://github.com/alibaba/spring-context-support/blob/1.0.2/src/main/java/com/alibaba/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java * * @since 2.6.6