diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java index 2de8f1364c..5afebe3340 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,10 @@ package org.springframework.messaging.handler.invocation; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -28,16 +30,14 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; -import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.target.EmptyTargetSource; import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; +import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodIntrospector; @@ -123,6 +123,7 @@ import static java.util.stream.Collectors.joining; * * * @author Rossen Stoyanchev + * @author Juergen Hoeller * @since 5.2 */ public class ResolvableMethod { @@ -189,7 +190,6 @@ public class ResolvableMethod { /** * Filter on method arguments with annotation. - * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final ArgResolver annot(Predicate... filter) { @@ -302,7 +302,6 @@ public class ResolvableMethod { /** * Filter on annotated methods. - * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final Builder annot(Predicate... filters) { @@ -313,7 +312,6 @@ public class ResolvableMethod { /** * Filter on methods annotated with the given annotation type. * @see #annot(Predicate[]) - * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final Builder annotPresent(Class... annotationTypes) { @@ -530,7 +528,6 @@ public class ResolvableMethod { /** * Filter on method arguments with annotations. - * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final ArgResolver annot(Predicate... filters) { @@ -542,7 +539,6 @@ public class ResolvableMethod { * Filter on method arguments that have the given annotations. * @param annotationTypes the annotation types * @see #annot(Predicate[]) - * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final ArgResolver annotPresent(Class... annotationTypes) { @@ -615,16 +611,10 @@ public class ResolvableMethod { } - private static class MethodInvocationInterceptor - implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor { + private static class MethodInvocationInterceptor implements MethodInterceptor, InvocationHandler { private Method invokedMethod; - - Method getInvokedMethod() { - return this.invokedMethod; - } - @Override @Nullable public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) { @@ -639,20 +629,23 @@ public class ResolvableMethod { @Override @Nullable - public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable { - return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null); + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return intercept(proxy, method, args, null); + } + + Method getInvokedMethod() { + return this.invokedMethod; } } + @SuppressWarnings("unchecked") private static T initProxy(Class type, MethodInvocationInterceptor interceptor) { Assert.notNull(type, "'type' must not be null"); if (type.isInterface()) { - ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); - factory.addInterface(type); - factory.addInterface(Supplier.class); - factory.addAdvice(interceptor); - return (T) factory.getProxy(); + return (T) Proxy.newProxyInstance(type.getClassLoader(), + new Class[] {type, Supplier.class}, + interceptor); } else { diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java index e4b5b7e610..520045ff4b 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,11 +84,12 @@ public class GenericMessageEndpointFactory extends AbstractMessageEndpointFactor @Override public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException { GenericMessageEndpoint endpoint = (GenericMessageEndpoint) super.createEndpoint(xaResource); - ProxyFactory proxyFactory = new ProxyFactory(getMessageListener()); + Object target = getMessageListener(); + ProxyFactory proxyFactory = new ProxyFactory(target); DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(endpoint); introduction.suppressInterface(MethodInterceptor.class); proxyFactory.addAdvice(introduction); - return (MessageEndpoint) proxyFactory.getProxy(); + return (MessageEndpoint) proxyFactory.getProxy(target.getClass().getClassLoader()); } /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java index f1967eb83c..2ad3eb4e20 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,10 @@ package org.springframework.web.testfixture.method; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -28,16 +30,14 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; -import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.target.EmptyTargetSource; import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; +import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodIntrospector; @@ -122,6 +122,7 @@ import static java.util.stream.Collectors.joining; * * * @author Rossen Stoyanchev + * @author Juergen Hoeller * @since 5.0 */ public class ResolvableMethod { @@ -614,16 +615,10 @@ public class ResolvableMethod { } - private static class MethodInvocationInterceptor - implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor { + private static class MethodInvocationInterceptor implements MethodInterceptor, InvocationHandler { private Method invokedMethod; - - Method getInvokedMethod() { - return this.invokedMethod; - } - @Override @Nullable public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) { @@ -638,20 +633,23 @@ public class ResolvableMethod { @Override @Nullable - public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable { - return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null); + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return intercept(proxy, method, args, null); + } + + Method getInvokedMethod() { + return this.invokedMethod; } } + @SuppressWarnings("unchecked") private static T initProxy(Class type, MethodInvocationInterceptor interceptor) { Assert.notNull(type, "'type' must not be null"); if (type.isInterface()) { - ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); - factory.addInterface(type); - factory.addInterface(Supplier.class); - factory.addAdvice(interceptor); - return (T) factory.getProxy(); + return (T) Proxy.newProxyInstance(type.getClassLoader(), + new Class[] {type, Supplier.class}, + interceptor); } else { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 80dcdd4110..ffced850f6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -25,17 +27,15 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; -import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.aop.target.EmptyTargetSource; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; +import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodIntrospector; @@ -93,6 +93,7 @@ import org.springframework.web.util.UriComponentsBuilder; * @author Oliver Gierke * @author Rossen Stoyanchev * @author Sam Brannen + * @author Juergen Hoeller * @since 4.0 */ public class MvcUriComponentsBuilder { @@ -700,7 +701,7 @@ public class MvcUriComponentsBuilder { private static class ControllerMethodInvocationInterceptor - implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor, MethodInvocationInfo { + implements MethodInterceptor, InvocationHandler, MethodInvocationInfo { private final Class controllerType; @@ -741,8 +742,8 @@ public class MvcUriComponentsBuilder { @Override @Nullable - public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable { - return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null); + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return intercept(proxy, method, args, null); } @Override @@ -767,19 +768,17 @@ public class MvcUriComponentsBuilder { private static T initProxy( Class controllerType, @Nullable ControllerMethodInvocationInterceptor interceptor) { - interceptor = interceptor != null ? - interceptor : new ControllerMethodInvocationInterceptor(controllerType); + interceptor = (interceptor != null ? + interceptor : new ControllerMethodInvocationInterceptor(controllerType)); if (controllerType == Object.class) { return (T) interceptor; } else if (controllerType.isInterface()) { - ProxyFactory factory = new ProxyFactory(EmptyTargetSource.INSTANCE); - factory.addInterface(controllerType); - factory.addInterface(MethodInvocationInfo.class); - factory.addAdvice(interceptor); - return (T) factory.getProxy(); + return (T) Proxy.newProxyInstance(controllerType.getClassLoader(), + new Class[] {controllerType, MethodInvocationInfo.class}, + interceptor); } else { @@ -787,7 +786,7 @@ public class MvcUriComponentsBuilder { enhancer.setSuperclass(controllerType); enhancer.setInterfaces(new Class[] {MethodInvocationInfo.class}); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); - enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); + enhancer.setCallbackType(MethodInterceptor.class); Class proxyClass = enhancer.createClass(); Object proxy = null;