Skip to content

Commit 83cf12a

Browse files
committed
Register projection interfaces for reflection and as resource.
Fixes GH-2526.
1 parent 7d1fea5 commit 83cf12a

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.aop.SpringProxy;
24+
import org.springframework.aot.hint.MemberCategory;
2425
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
2526
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
2627
import org.springframework.beans.factory.support.RegisteredBean;
2728
import org.springframework.core.DecoratingProxy;
2829
import org.springframework.core.io.DefaultResourceLoader;
30+
import org.springframework.core.io.Resource;
31+
import org.springframework.core.io.ResourceLoader;
2932
import org.springframework.data.projection.TargetAware;
3033
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
3134
import org.springframework.data.rest.core.config.Projection;
@@ -34,14 +37,14 @@
3437
import org.springframework.util.ObjectUtils;
3538

3639
/**
37-
* {@link BeanRegistrationAotProcessor} to register proxy hints for projection interfaces.
40+
* {@link BeanRegistrationAotProcessor} to register proxy and resource hints for projection interfaces.
3841
*
3942
* @author Oliver Drotbohm
4043
* @since 4.0
4144
*/
42-
class ProjectionProxyAotProcessor implements BeanRegistrationAotProcessor {
45+
class ProjectionAotProcessor implements BeanRegistrationAotProcessor {
4346

44-
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionProxyAotProcessor.class);
47+
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionAotProcessor.class);
4548

4649
private static Class<?>[] ADDITIONAL_INTERFACES = new Class<?>[] { //
4750
TargetAware.class, //
@@ -76,18 +79,30 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe
7679
return (context, code) -> {
7780

7881
var classLoader = registeredBean.getBeanFactory().getBeanClassLoader();
79-
var proxies = context.getRuntimeHints().proxies();
82+
var hints = context.getRuntimeHints();
83+
84+
var resourceLoader = new DefaultResourceLoader(classLoader);
8085

8186
var scanner = new AnnotatedTypeScanner(Projection.class);
82-
scanner.setResourceLoader(new DefaultResourceLoader(classLoader));
87+
scanner.setResourceLoader(resourceLoader);
8388
scanner.findTypes(packageToScan)
8489
.forEach(it -> {
8590

86-
LOGGER.debug("Registering proxy config for projection interface {}.", it.getName());
91+
LOGGER.debug("Registering proxy config and resource for projection interface {}.", it.getName());
8792

88-
proxies.registerJdkProxy(ObjectUtils.addObjectToArray(ADDITIONAL_INTERFACES, it, 0));
93+
hints.reflection().registerType(it, MemberCategory.INVOKE_PUBLIC_METHODS);
94+
hints.resources().registerResource(getResource(it, resourceLoader));
95+
hints.proxies().registerJdkProxy(ObjectUtils.addObjectToArray(ADDITIONAL_INTERFACES, it, 0));
8996
});
9097

9198
};
9299
}
100+
101+
private static Resource getResource(Class<?> type, ResourceLoader loader) {
102+
103+
var resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
104+
ClassUtils.convertClassNameToResourcePath(type.getName()) + ClassUtils.CLASS_FILE_SUFFIX;
105+
106+
return loader.getResource(resourcePath);
107+
}
93108
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
22
org.springframework.data.rest.webmvc.aot.BasePathAwareControllerAotProcessor,\
3-
org.springframework.data.rest.webmvc.aot.ProjectionProxyAotProcessor
3+
org.springframework.data.rest.webmvc.aot.ProjectionAotProcessor
44
org.springframework.aot.hint.RuntimeHintsRegistrar=\
55
org.springframework.data.rest.webmvc.aot.ValueInstantiatorCustomizerRuntimeHints,\
66
org.springframework.data.rest.webmvc.aot.RestMessagesResourcesRuntimeHints

0 commit comments

Comments
 (0)