DATACMNS-1754 - Support implementation lookup for nested repositories and fragments.

Problem: while repository and fragment interfaces are discovered
correctly (provided that considerNestedRepositories=true), their
implementations are not found/registered despite proper class naming.

Cause: DefaultImplementationLookupConfiguration works in such way that
for nested interface (i.e. one whose class name includes name of the
enclosing class) expected implementation class name is built including
that enclosing class name. In the same time actual implementation class
names are always "localized" (i.e. stripped from enclosing class name,
if any) before matching. This makes matching implementation classes
against nested interface impossible.

Solution: when building expected implementation class name, use "local"
interface class name, so that it can match any implementation class that
follows naming convention "SimpleInterfaceName" + "ImplemenetationPostfix".

Original pull request: #460.
This commit is contained in:
Kyrylo Merzlikin
2020-07-18 18:49:36 +03:00
committed by Mark Paluch
parent c99f2c9459
commit 2a44d2394c
7 changed files with 125 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils;
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Kyrylo Merzlikin
* @since 2.1
*/
class DefaultImplementationLookupConfiguration implements ImplementationLookupConfiguration {
@@ -55,8 +56,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
this.config = config;
this.interfaceName = interfaceName;
this.beanName = Introspector
.decapitalize(ClassUtils.getShortName(interfaceName).concat(config.getImplementationPostfix()));
this.beanName = Introspector.decapitalize(getLocalName(interfaceName).concat(config.getImplementationPostfix()));
}
/*
@@ -110,7 +110,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
*/
@Override
public String getImplementationClassName() {
return ClassUtils.getShortName(interfaceName).concat(getImplementationPostfix());
return getLocalName(interfaceName).concat(getImplementationPostfix());
}
/*
@@ -141,13 +141,18 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
}
String beanPackage = ClassUtils.getPackageName(beanClassName);
String shortName = ClassUtils.getShortName(beanClassName);
String localName = shortName.substring(shortName.lastIndexOf('.') + 1);
String localName = getLocalName(beanClassName);
return localName.equals(getImplementationClassName()) //
&& getBasePackages().stream().anyMatch(it -> beanPackage.startsWith(it));
}
private String getLocalName(String className) {
String shortName = ClassUtils.getShortName(className);
return shortName.substring(shortName.lastIndexOf('.') + 1);
}
private boolean isExcluded(String beanClassName, Streamable<TypeFilter> filters) {
try {