diff --git a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java index 16556e2282..38b419bc79 100644 --- a/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java +++ b/src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryInformation.java @@ -372,6 +372,10 @@ private boolean parametersMatch(Method method, Method baseClassMethod) { continue; } + if (types[i].equals(parameterType)) { + continue; + } + if (!type.isAssignableFrom(parameterType) || !type.equals(methodParameterTypes[i])) { return false; } diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java index 5d4bd40d93..1f4b0ce591 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java @@ -223,12 +223,12 @@ public void discoversCustomlyImplementedCrudMethodWithGenerics() throws Security @Test // DATACMNS-912 public void discoversCustomlyImplementedCrudMethodWithGenericParameters() throws Exception { - SampleRepositoryImpl customImplementation = new SampleRepositoryImpl(); - RepositoryMetadata metadata = new DefaultRepositoryMetadata(SampleRepository.class); + GenericsSaveRepositoryImpl customImplementation = new GenericsSaveRepositoryImpl(); + RepositoryMetadata metadata = new DefaultRepositoryMetadata(GenericsSaveRepository.class); RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class, customImplementation.getClass()); - Method customBaseRepositoryMethod = SampleRepository.class.getMethod("save", Object.class); + Method customBaseRepositoryMethod = GenericsSaveRepository.class.getMethod("save", Object.class); assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true)); } @@ -244,6 +244,18 @@ public void usesCorrectSaveOverload() throws Exception { is(DummyRepositoryImpl.class.getMethod("save", Iterable.class))); } + @Test // DATACMNS-1008, DATACMNS-912, DATACMNS-854 + public void discoversCustomlyImplementedCrudMethodWithoutGenericParameters() throws Exception { + + SimpleSaveRepositoryImpl customImplementation = new SimpleSaveRepositoryImpl(); + RepositoryMetadata metadata = new DefaultRepositoryMetadata(SimpleSaveRepository.class); + RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class, + customImplementation.getClass()); + + Method customBaseRepositoryMethod = SimpleSaveRepository.class.getMethod("save", Object.class); + assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true)); + } + private static Method getMethodFrom(Class type, String name) { for (Method method : type.getMethods()) { @@ -346,11 +358,13 @@ interface CustomDefaultRepositoryMethodsRepository extends CrudRepository findAll(); } - interface SampleRepository extends CrudRepository {} + // DATACMNS-854, DATACMNS-912 + + interface GenericsSaveRepository extends CrudRepository {} - static class SampleRepositoryImpl { + static class GenericsSaveRepositoryImpl { - public S save(S entity) { + public T save(T entity) { return entity; } } @@ -367,4 +381,15 @@ static class DummyRepositoryImpl implements CrudRepo private @Delegate CrudRepository delegate; } + + // DATACMNS-1008, DATACMNS-854, DATACMNS-912 + + interface SimpleSaveRepository extends CrudRepository {} + + static class SimpleSaveRepositoryImpl { + + public Sample save(Sample entity) { + return entity; + } + } }