diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 4c71d9ad83c..f59e60ea30c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -25,7 +25,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -46,6 +45,7 @@ import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.support.ClassHintUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; @@ -1018,10 +1018,10 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA private void registerProxyIfNecessary(RuntimeHints runtimeHints, DependencyDescriptor dependencyDescriptor) { if (this.candidateResolver != null) { - Class> proxyType = + Class> proxyClass = this.candidateResolver.getLazyResolutionProxyClass(dependencyDescriptor, null); - if (proxyType != null && Proxy.isProxyClass(proxyType)) { - runtimeHints.proxies().registerJdkProxy(proxyType.getInterfaces()); + if (proxyClass != null) { + ClassHintUtils.registerProxyIfNecessary(proxyClass, runtimeHints); } } } diff --git a/spring-context/src/main/java/org/springframework/context/aot/CglibClassHandler.java b/spring-context/src/main/java/org/springframework/context/aot/CglibClassHandler.java index 4401342fd81..61b393f801f 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/CglibClassHandler.java +++ b/spring-context/src/main/java/org/springframework/context/aot/CglibClassHandler.java @@ -16,7 +16,6 @@ package org.springframework.context.aot; -import java.util.function.BiConsumer; import java.util.function.Consumer; import org.springframework.aot.generate.GeneratedFiles; @@ -26,6 +25,7 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeHint.Builder; import org.springframework.aot.hint.TypeReference; +import org.springframework.aot.hint.support.ClassHintUtils; import org.springframework.cglib.core.ReflectUtils; import org.springframework.core.io.ByteArrayResource; @@ -34,8 +34,10 @@ import org.springframework.core.io.ByteArrayResource; * and register the necessary hints so that they can be instantiated. * * @author Stephane Nicoll - * @see ReflectUtils#setGeneratedClassHandler(BiConsumer) - * @see ReflectUtils#setLoadedClassHandler(Consumer) + * @since 6.0 + * @see ReflectUtils#setGeneratedClassHandler + * @see ReflectUtils#setLoadedClassHandler + * @see ClassHintUtils#registerProxyIfNecessary */ class CglibClassHandler { @@ -46,11 +48,13 @@ class CglibClassHandler { private final GeneratedFiles generatedFiles; + CglibClassHandler(GenerationContext generationContext) { this.runtimeHints = generationContext.getRuntimeHints(); this.generatedFiles = generationContext.getGeneratedFiles(); } + /** * Handle the specified generated CGLIB class. * @param cglibClassName the name of the generated class diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java index 2efd033d599..c172acc02d8 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java @@ -18,15 +18,12 @@ package org.springframework.context.support; import java.io.IOException; import java.lang.reflect.Constructor; -import java.lang.reflect.Proxy; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; import java.util.function.Supplier; -import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.TypeHint.Builder; +import org.springframework.aot.hint.support.ClassHintUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -49,7 +46,6 @@ import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.metrics.ApplicationStartup; import org.springframework.lang.Nullable; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * Generic ApplicationContext implementation that holds a single internal @@ -72,7 +68,7 @@ import org.springframework.util.ClassUtils; * definitions on it. {@link #refresh()} may only be called once. * *
This ApplicationContext implementation is suitable for Ahead of Time - * processing, using {@link #refreshForAotProcessing()} as an alternative to the + * processing, using {@link #refreshForAotProcessing} as an alternative to the * regular {@link #refresh()}. * *
Usage example: @@ -88,16 +84,13 @@ import org.springframework.util.ClassUtils; * MyBean myBean = (MyBean) ctx.getBean("myBean"); * ... * - * For the typical case of XML bean definitions, simply use + * For the typical case of XML bean definitions, you may also use * {@link ClassPathXmlApplicationContext} or {@link FileSystemXmlApplicationContext}, * which are easier to set up - but less flexible, since you can just use standard * resource locations for XML bean definitions, rather than mixing arbitrary bean - * definition formats. The equivalent in a web environment is - * {@link org.springframework.web.context.support.XmlWebApplicationContext}. - * - *
For custom application context implementations that are supposed to read
- * special bean definition formats in a refreshable manner, consider deriving
- * from the {@link AbstractRefreshableApplicationContext} base class.
+ * definition formats. For a custom application context implementation supposed to
+ * read a specific bean definition format in a refreshable manner, consider
+ * deriving from the {@link AbstractRefreshableApplicationContext} base class.
*
* @author Juergen Hoeller
* @author Chris Beams
@@ -111,15 +104,6 @@ import org.springframework.util.ClassUtils;
*/
public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry {
- private static final Consumer Note that this class does not take specifics of Spring AOP or
+ * any other framework arrangement into account. It just operates
+ * on the JDK and CGLIB proxy facilities and their core conventions.
+ *
+ * @author Juergen Hoeller
+ * @since 6.0.3
+ * @see org.springframework.aot.hint.ProxyHints
+ * @see org.springframework.aot.hint.ReflectionHints
+ */
+public abstract class ClassHintUtils {
+
+ private static final Consumer