Skip to content

Commit 0937040

Browse files
committed
Register projection interfaces for reflection and as resource.
Fixes GH-2526.
1 parent 209128d commit 0937040

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
@@ -22,11 +22,14 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424
import org.springframework.aop.SpringProxy;
25+
import org.springframework.aot.hint.MemberCategory;
2526
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
2627
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
2728
import org.springframework.beans.factory.support.RegisteredBean;
2829
import org.springframework.core.DecoratingProxy;
2930
import org.springframework.core.io.DefaultResourceLoader;
31+
import org.springframework.core.io.Resource;
32+
import org.springframework.core.io.ResourceLoader;
3033
import org.springframework.data.projection.TargetAware;
3134
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
3235
import org.springframework.data.rest.core.config.Projection;
@@ -35,14 +38,14 @@
3538
import org.springframework.util.ObjectUtils;
3639

3740
/**
38-
* {@link BeanRegistrationAotProcessor} to register proxy hints for projection interfaces.
41+
* {@link BeanRegistrationAotProcessor} to register proxy and resource hints for projection interfaces.
3942
*
4043
* @author Oliver Drotbohm
4144
* @since 4.0
4245
*/
43-
class ProjectionProxyAotProcessor implements BeanRegistrationAotProcessor {
46+
class ProjectionAotProcessor implements BeanRegistrationAotProcessor {
4447

45-
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionProxyAotProcessor.class);
48+
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionAotProcessor.class);
4649

4750
private static final Class<?>[] ADDITIONAL_INTERFACES = new Class<?>[] { //
4851
TargetAware.class, //
@@ -82,18 +85,30 @@ class ProjectionProxyAotProcessor implements BeanRegistrationAotProcessor {
8285
return (context, code) -> {
8386

8487
var classLoader = registeredBean.getBeanFactory().getBeanClassLoader();
85-
var proxies = context.getRuntimeHints().proxies();
88+
var hints = context.getRuntimeHints();
89+
90+
var resourceLoader = new DefaultResourceLoader(classLoader);
8691

8792
var scanner = new AnnotatedTypeScanner(Projection.class);
88-
scanner.setResourceLoader(new DefaultResourceLoader(classLoader));
93+
scanner.setResourceLoader(resourceLoader);
8994
scanner.findTypes(packageToScan)
9095
.forEach(it -> {
9196

92-
LOGGER.debug("Registering proxy config for projection interface {}.", it.getName());
97+
LOGGER.debug("Registering proxy config and resource for projection interface {}.", it.getName());
9398

94-
proxies.registerJdkProxy(ObjectUtils.addObjectToArray(ADDITIONAL_INTERFACES, it, 0));
99+
hints.reflection().registerType(it, MemberCategory.INVOKE_PUBLIC_METHODS);
100+
hints.resources().registerResource(getResource(it, resourceLoader));
101+
hints.proxies().registerJdkProxy(ObjectUtils.addObjectToArray(ADDITIONAL_INTERFACES, it, 0));
95102
});
96103

97104
};
98105
}
106+
107+
private static Resource getResource(Class<?> type, ResourceLoader loader) {
108+
109+
var resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
110+
ClassUtils.convertClassNameToResourcePath(type.getName()) + ClassUtils.CLASS_FILE_SUFFIX;
111+
112+
return loader.getResource(resourcePath);
113+
}
99114
}
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)