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