DATACMNS-1439 - Use Java Beans decapitalization for default repository implementation bean names.
We now use Java Beans Introspector during default bean name derivation from class names. Previously, we used String.decapitalize(…) which decapitalizes always the first character. Java Beans do not decapitalize upper case sequences so a class name com.acme.UDPRepository translates to a bean name with UDPRepository instead of uDPRepository. Original pull request: #325.
This commit is contained in:
committed by
Oliver Drotbohm
parent
fe1ccd50be
commit
9fe35a24c9
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.repository.config;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -32,6 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
* Default implementation of {@link ImplementationLookupConfiguration}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @since 2.1
|
||||
*/
|
||||
class DefaultImplementationLookupConfiguration implements ImplementationLookupConfiguration {
|
||||
@@ -54,8 +56,7 @@ class DefaultImplementationLookupConfiguration implements ImplementationLookupCo
|
||||
|
||||
this.config = config;
|
||||
this.interfaceName = interfaceName;
|
||||
this.beanName = StringUtils
|
||||
.uncapitalize(ClassUtils.getShortName(interfaceName).concat(config.getImplementationPostfix()));
|
||||
this.beanName = Introspector.decapitalize(ClassUtils.getShortName(interfaceName).concat(config.getImplementationPostfix()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.repository.config;
|
||||
|
||||
import java.beans.Introspector;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Expresses configuration to be used to detect implementation classes for repositories and repository fragments.
|
||||
@@ -75,7 +76,7 @@ public interface ImplementationDetectionConfiguration {
|
||||
throw new IllegalStateException("Cannot generate bean name for BeanDefinition without bean class name!");
|
||||
}
|
||||
|
||||
return StringUtils.uncapitalize(ClassUtils.getShortName(beanName));
|
||||
return Introspector.decapitalize(ClassUtils.getShortName(beanName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,13 +17,13 @@ package org.springframework.data.repository.config;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.data.config.ConfigurationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Fragment configuration consisting of an interface name and the implementation class name.
|
||||
@@ -76,7 +76,7 @@ public class RepositoryFragmentConfiguration {
|
||||
* @return name of the implementation bean.
|
||||
*/
|
||||
public String getImplementationBeanName() {
|
||||
return StringUtils.uncapitalize(ClassUtils.getShortName(getClassName()));
|
||||
return Introspector.decapitalize(ClassUtils.getShortName(getClassName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user