Skip to content

Commit 314e8d5

Browse files
committed
GH-1541 - Skip non-interfaces from Spring Data repository detection.
1 parent 738b222 commit 314e8d5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/Types.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ static boolean isPresent() {
292292
}
293293

294294
static DescribedPredicate<JavaClass> isSpringDataRepository() {
295-
return is(assignableTo(SpringDataTypes.REPOSITORY)) //
296-
.or(isAnnotatedWith(SpringDataTypes.AT_REPOSITORY_DEFINITION));
295+
296+
return isInterface().and(is(assignableTo(SpringDataTypes.REPOSITORY)) //
297+
.or(isAnnotatedWith(SpringDataTypes.AT_REPOSITORY_DEFINITION)));
297298
}
298299
}
299300

@@ -321,4 +322,21 @@ public boolean test(JavaClass t) {
321322
}
322323
};
323324
}
325+
326+
/**
327+
* A {@link DescribedPredicate} matching only interfaces.
328+
*
329+
* @return will never be {@literal null}.
330+
* @since 2.1, 2.0.3, 1.4.8
331+
*/
332+
static DescribedPredicate<JavaClass> isInterface() {
333+
334+
return new DescribedPredicate<>("is an interface") {
335+
336+
@Override
337+
public boolean test(JavaClass t) {
338+
return t.isInterface();
339+
}
340+
};
341+
}
324342
}

spring-modulith-core/src/test/java/org/springframework/modulith/core/ArchitecturallyEvidentTypeUnitTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void doesNotConsiderEntityAggregateRoot() {
107107
assertThat(type.isAggregateRoot()).isFalse();
108108
}
109109

110-
@Test
110+
@Test // GH-1, GH-1541
111111
void considersEntityAnAggregateRootIfTheresARepositoryForIt() {
112112

113113
Map<Class<?>, Boolean> parameters = new HashMap<Class<?>, Boolean>();
@@ -235,6 +235,9 @@ class SampleEntity {}
235235

236236
interface SampleRepository extends CrudRepository<SampleEntity, UUID> {}
237237

238+
// GH-1541
239+
abstract class IntermediateImplementation implements CrudRepository<SampleEntity, UUID> {}
240+
238241
// GH-187
239242
interface ReactiveSampleRepository extends ReactiveCrudRepository<SampleEntity, UUID> {}
240243

0 commit comments

Comments
 (0)