|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.repository.support;
|
17 | 17 |
|
| 18 | +import java.lang.reflect.AnnotatedElement; |
18 | 19 | import java.lang.reflect.Method;
|
19 | 20 | import java.util.HashSet;
|
20 | 21 | import java.util.Optional;
|
@@ -179,28 +180,25 @@ static class DefaultCrudMethodMetadata implements CrudMethodMetadata {
|
179 | 180 | */
|
180 | 181 | DefaultCrudMethodMetadata(Class<?> repositoryInterface, Method method) {
|
181 | 182 |
|
| 183 | + Assert.notNull(repositoryInterface, "Repository interface must not be null"); |
182 | 184 | Assert.notNull(method, "Method must not be null");
|
183 | 185 |
|
184 |
| - this.readPreference = findReadPreference(repositoryInterface, method); |
| 186 | + this.readPreference = findReadPreference(method, repositoryInterface); |
185 | 187 | }
|
186 | 188 |
|
187 |
| - private Optional<ReadPreference> findReadPreference(Class<?> repositoryInterface, Method method) { |
| 189 | + private static Optional<ReadPreference> findReadPreference(AnnotatedElement... annotatedElements) { |
188 | 190 |
|
189 |
| - org.springframework.data.mongodb.repository.ReadPreference preference = AnnotatedElementUtils |
190 |
| - .findMergedAnnotation(method, org.springframework.data.mongodb.repository.ReadPreference.class); |
| 191 | + for (AnnotatedElement element : annotatedElements) { |
191 | 192 |
|
192 |
| - if (preference == null) { |
| 193 | + org.springframework.data.mongodb.repository.ReadPreference preference = AnnotatedElementUtils |
| 194 | + .findMergedAnnotation(element, org.springframework.data.mongodb.repository.ReadPreference.class); |
193 | 195 |
|
194 |
| - preference = AnnotatedElementUtils.findMergedAnnotation(repositoryInterface, |
195 |
| - org.springframework.data.mongodb.repository.ReadPreference.class); |
196 |
| - } |
197 |
| - |
198 |
| - if (preference == null) { |
199 |
| - return Optional.empty(); |
| 196 | + if (preference != null) { |
| 197 | + return Optional.of(com.mongodb.ReadPreference.valueOf(preference.value())); |
| 198 | + } |
200 | 199 | }
|
201 | 200 |
|
202 |
| - return Optional.of(com.mongodb.ReadPreference.valueOf(preference.value())); |
203 |
| - |
| 201 | + return Optional.empty(); |
204 | 202 | }
|
205 | 203 |
|
206 | 204 | @Override
|
|
0 commit comments