Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Reference auto-wires the instance of generic interface #4594 #4677

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
beiwei30 marked this conversation as resolved.
Show resolved Hide resolved
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