|
22 | 22 | import org.slf4j.Logger; |
23 | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | import org.springframework.aop.SpringProxy; |
| 25 | +import org.springframework.aot.hint.MemberCategory; |
25 | 26 | import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; |
26 | 27 | import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; |
27 | 28 | import org.springframework.beans.factory.support.RegisteredBean; |
28 | 29 | import org.springframework.core.DecoratingProxy; |
29 | 30 | import org.springframework.core.io.DefaultResourceLoader; |
| 31 | +import org.springframework.core.io.Resource; |
| 32 | +import org.springframework.core.io.ResourceLoader; |
30 | 33 | import org.springframework.data.projection.TargetAware; |
31 | 34 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; |
32 | 35 | import org.springframework.data.rest.core.config.Projection; |
|
35 | 38 | import org.springframework.util.ObjectUtils; |
36 | 39 |
|
37 | 40 | /** |
38 | | - * {@link BeanRegistrationAotProcessor} to register proxy hints for projection interfaces. |
| 41 | + * {@link BeanRegistrationAotProcessor} to register proxy and resource hints for projection interfaces. |
39 | 42 | * |
40 | 43 | * @author Oliver Drotbohm |
41 | 44 | * @since 4.0 |
42 | 45 | */ |
43 | | -class ProjectionProxyAotProcessor implements BeanRegistrationAotProcessor { |
| 46 | +class ProjectionAotProcessor implements BeanRegistrationAotProcessor { |
44 | 47 |
|
45 | | - private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionProxyAotProcessor.class); |
| 48 | + private static final Logger LOGGER = LoggerFactory.getLogger(ProjectionAotProcessor.class); |
46 | 49 |
|
47 | 50 | private static final Class<?>[] ADDITIONAL_INTERFACES = new Class<?>[] { // |
48 | 51 | TargetAware.class, // |
@@ -82,18 +85,30 @@ class ProjectionProxyAotProcessor implements BeanRegistrationAotProcessor { |
82 | 85 | return (context, code) -> { |
83 | 86 |
|
84 | 87 | var classLoader = registeredBean.getBeanFactory().getBeanClassLoader(); |
85 | | - var proxies = context.getRuntimeHints().proxies(); |
| 88 | + var hints = context.getRuntimeHints(); |
| 89 | + |
| 90 | + var resourceLoader = new DefaultResourceLoader(classLoader); |
86 | 91 |
|
87 | 92 | var scanner = new AnnotatedTypeScanner(Projection.class); |
88 | | - scanner.setResourceLoader(new DefaultResourceLoader(classLoader)); |
| 93 | + scanner.setResourceLoader(resourceLoader); |
89 | 94 | scanner.findTypes(packageToScan) |
90 | 95 | .forEach(it -> { |
91 | 96 |
|
92 | | - LOGGER.debug("Registering proxy config for projection interface {}.", it.getName()); |
| 97 | + LOGGER.debug("Registering proxy config and resource for projection interface {}.", it.getName()); |
93 | 98 |
|
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)); |
95 | 102 | }); |
96 | 103 |
|
97 | 104 | }; |
98 | 105 | } |
| 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 | + } |
99 | 114 | } |
0 commit comments