Skip to content

Commit 7625dd3

Browse files
committed
DATACMNS-466 - More aggressive checks for the correct Spring version.
We now actively check that the a method in a Spring class we rely on to be public actually is public and throw an exception pointing to the offending JAR in an exception that's thrown otherwise.
1 parent 88af0cb commit 7625dd3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/org/springframework/data/repository/config/RepositoryComponentProvider.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,8 @@
4444
*/
4545
class RepositoryComponentProvider extends ClassPathScanningCandidateComponentProvider {
4646

47+
private static final String METHOD_NOT_PUBLIC = "AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from %s.";
48+
4749
private boolean considerNestedRepositoryInterfaces;
4850

4951
/**
@@ -57,6 +59,8 @@ public RepositoryComponentProvider(Iterable<? extends TypeFilter> includeFilters
5759

5860
super(false);
5961

62+
assertRequiredSpringVersionPresent();
63+
6064
Assert.notNull(includeFilters);
6165

6266
if (includeFilters.iterator().hasNext()) {
@@ -142,6 +146,20 @@ public void setConsiderNestedRepositoryInterfaces(boolean considerNestedReposito
142146
this.considerNestedRepositoryInterfaces = considerNestedRepositoryInterfaces;
143147
}
144148

149+
/**
150+
* Makes sure {@link AnnotationConfigUtils#processCommonDefinitionAnnotations(AnnotatedBeanDefinition) is public and
151+
* indicates the offending JAR if not.
152+
*/
153+
private static void assertRequiredSpringVersionPresent() {
154+
155+
try {
156+
AnnotationConfigUtils.class.getMethod("processCommonDefinitionAnnotations", AnnotatedBeanDefinition.class);
157+
} catch (NoSuchMethodException o_O) {
158+
throw new IllegalStateException(String.format(METHOD_NOT_PUBLIC, AnnotationConfigUtils.class
159+
.getProtectionDomain().getCodeSource().getLocation()), o_O);
160+
}
161+
}
162+
145163
/**
146164
* {@link org.springframework.core.type.filter.TypeFilter} that only matches interfaces. Thus setting this up makes
147165
* only sense providing an interface type as {@code targetType}.

0 commit comments

Comments
 (0)