Skip to content

Commit e356e9d

Browse files
mp911dechristophstrobl
authored andcommitted
Refine BPP assignability check.
1 parent bfa1466 commit e356e9d

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

mongodb/fragment-spi/atlas-api/src/main/java/com/example/spi/mongodb/atlas/AtlasRepositoryPostProcessor.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,24 @@
1515
*/
1616
package com.example.spi.mongodb.atlas;
1717

18-
import java.lang.reflect.Field;
19-
import java.util.Arrays;
20-
2118
import org.springframework.beans.BeansException;
2219
import org.springframework.beans.factory.config.BeanPostProcessor;
2320
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
24-
import org.springframework.stereotype.Component;
25-
import org.springframework.util.ReflectionUtils;
2621

2722
/**
2823
* @author Christoph Strobl
2924
*/
3025
class AtlasRepositoryPostProcessor implements BeanPostProcessor {
3126

32-
@Override
33-
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
27+
@Override
28+
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
3429

35-
if (bean instanceof RepositoryFactoryBeanSupport rfbs) {
30+
if (bean instanceof RepositoryFactoryBeanSupport rfbs) {
3631

37-
Field field = ReflectionUtils.findField(RepositoryFactoryBeanSupport.class, "repositoryInterface");
38-
ReflectionUtils.makeAccessible(field);
39-
if (Arrays.stream(((Class<?>) ReflectionUtils.getField(field, rfbs)).getInterfaces())
40-
.anyMatch(iface -> {
41-
return iface.equals(AtlasRepository.class);
42-
})) {
43-
rfbs.setExposeMetadata(true);
44-
}
45-
}
46-
return bean;
47-
}
32+
if (AtlasRepository.class.isAssignableFrom(rfbs.getObjectType())) {
33+
rfbs.setExposeMetadata(true);
34+
}
35+
}
36+
return bean;
37+
}
4838
}

0 commit comments

Comments
 (0)