Skip to content

Commit

Permalink
@reference auto-wires the instance of generic interface apache#4594
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingSinger committed Jul 26, 2019
1 parent f2af6fd commit 14657de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;

import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAttributes;
Expand Down Expand Up @@ -57,6 +56,15 @@ private ReferenceBeanBuilder(AnnotationAttributes attributes, ApplicationContext
}

private void configureInterface(AnnotationAttributes attributes, ReferenceBean referenceBean) {
Boolean generic = getAttribute(attributes, "generic");
if (generic != null && generic) {
// it's a generic reference
String interfaceClassName = getAttribute(attributes, "interfaceName");
Assert.hasText(interfaceClassName,
"@Reference interfaceName() must be present when reference a generic service!");
referenceBean.setInterface(interfaceClassName);
return;
}

Class<?> serviceInterfaceClass = resolveServiceInterfaceClass(attributes, interfaceClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;

import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertyResolver;
Expand Down Expand Up @@ -93,6 +92,14 @@ public static String resolveInterfaceName(Service service, Class<?> defaultInter
* @throws IllegalStateException if interface name was not found
*/
public static String resolveInterfaceName(AnnotationAttributes attributes, Class<?> defaultInterfaceClass) {
Boolean generic = getAttribute(attributes, "generic");
if (generic != null && generic) {
// it's a generic reference
String interfaceClassName = getAttribute(attributes, "interfaceName");
Assert.hasText(interfaceClassName,
"@Reference interfaceName() must be present when reference a generic service!");
return interfaceClassName;
}
return resolveServiceInterfaceClass(attributes, defaultInterfaceClass).getName();
}

Expand Down

0 comments on commit 14657de

Please sign in to comment.