提交 7c25c84e 编写于 作者: C Chris Beams

Deprecate/move CGLIB methods AopUtils=>ClassUtils

isCglibProxy* methods in AopUtils are useful in lower-level modules,
i.e. those that cannot depend on .aop.  Therefore copied these methods
to ClassUtils; deprecated the existing ones in AopUtils and now
delegating to the new location; switched all usage of
AopUtils#isCglibProxy* within the framework to use
ClassUtils#isCglibProxy* instead.
上级 78b60947
...@@ -35,11 +35,11 @@ import net.sf.cglib.proxy.MethodInterceptor; ...@@ -35,11 +35,11 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.MethodProxy;
import net.sf.cglib.proxy.NoOp; import net.sf.cglib.proxy.NoOp;
import net.sf.cglib.transform.impl.UndeclaredThrowableStrategy; import net.sf.cglib.transform.impl.UndeclaredThrowableStrategy;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.Advisor; import org.springframework.aop.Advisor;
import org.springframework.aop.PointcutAdvisor; import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.RawTargetAccess; import org.springframework.aop.RawTargetAccess;
...@@ -47,6 +47,7 @@ import org.springframework.aop.TargetSource; ...@@ -47,6 +47,7 @@ import org.springframework.aop.TargetSource;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.core.SmartClassLoader; import org.springframework.core.SmartClassLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
...@@ -155,7 +156,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable { ...@@ -155,7 +156,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy"); Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy");
Class proxySuperClass = rootClass; Class proxySuperClass = rootClass;
if (AopUtils.isCglibProxyClass(rootClass)) { if (ClassUtils.isCglibProxyClass(rootClass)) {
proxySuperClass = rootClass.getSuperclass(); proxySuperClass = rootClass.getSuperclass();
Class[] additionalInterfaces = rootClass.getInterfaces(); Class[] additionalInterfaces = rootClass.getInterfaces();
for (Class additionalInterface : additionalInterfaces) { for (Class additionalInterface : additionalInterfaces) {
......
...@@ -63,7 +63,7 @@ public abstract class AopUtils { ...@@ -63,7 +63,7 @@ public abstract class AopUtils {
*/ */
public static boolean isAopProxy(Object object) { public static boolean isAopProxy(Object object) {
return (object instanceof SpringProxy && return (object instanceof SpringProxy &&
(Proxy.isProxyClass(object.getClass()) || isCglibProxyClass(object.getClass()))); (Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass())));
} }
/** /**
...@@ -76,27 +76,34 @@ public abstract class AopUtils { ...@@ -76,27 +76,34 @@ public abstract class AopUtils {
} }
/** /**
* Check whether the given object is a CGLIB proxy. * Check whether the given object is a CGLIB proxy. Goes beyond the implementation
* in {@link ClassUtils#isCglibProxy(Object)} by checking also to see if the given
* object is an instance of {@link SpringProxy}.
* @param object the object to check * @param object the object to check
* @see ClassUtils#isCglibProxy(Object)
*/ */
public static boolean isCglibProxy(Object object) { public static boolean isCglibProxy(Object object) {
return (object instanceof SpringProxy && isCglibProxyClass(object.getClass())); return (object instanceof SpringProxy && ClassUtils.isCglibProxy(object));
} }
/** /**
* Check whether the specified class is a CGLIB-generated class. * Check whether the specified class is a CGLIB-generated class.
* @param clazz the class to check * @param clazz the class to check
* @deprecated as of Spring 3.1 in favor of {@link ClassUtils#isCglibProxyClass(Class)}
*/ */
@Deprecated
public static boolean isCglibProxyClass(Class<?> clazz) { public static boolean isCglibProxyClass(Class<?> clazz) {
return (clazz != null && isCglibProxyClassName(clazz.getName())); return ClassUtils.isCglibProxyClass(clazz);
} }
/** /**
* Check whether the specified class name is a CGLIB-generated class. * Check whether the specified class name is a CGLIB-generated class.
* @param className the class name to check * @param className the class name to check
* @deprecated as of Spring 3.1 in favor of {@link ClassUtils#isCglibProxyClassName(String)}
*/ */
@Deprecated
public static boolean isCglibProxyClassName(String className) { public static boolean isCglibProxyClassName(String className) {
return (className != null && className.contains(ClassUtils.CGLIB_CLASS_SEPARATOR)); return ClassUtils.isCglibProxyClassName(className);
} }
/** /**
......
...@@ -21,7 +21,6 @@ import static org.junit.Assert.assertThat; ...@@ -21,7 +21,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
...@@ -29,6 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -29,6 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.util.ClassUtils;
import test.beans.TestBean; import test.beans.TestBean;
...@@ -54,7 +54,7 @@ public class ImportedConfigurationClassEnhancementTests { ...@@ -54,7 +54,7 @@ public class ImportedConfigurationClassEnhancementTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses); ApplicationContext ctx = new AnnotationConfigApplicationContext(configClasses);
Config config = ctx.getBean(Config.class); Config config = ctx.getBean(Config.class);
assertTrue("autowired config class has not been enhanced", assertTrue("autowired config class has not been enhanced",
AopUtils.isCglibProxyClass(config.autowiredConfig.getClass())); ClassUtils.isCglibProxy(config.autowiredConfig));
} }
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
package org.springframework.context.annotation.configuration; package org.springframework.context.annotation.configuration;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*; import static org.junit.Assert.assertThat;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import org.springframework.aop.support.AopUtils; import org.junit.Test;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
...@@ -29,6 +29,7 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -29,6 +29,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
public class Spr7167Tests { public class Spr7167Tests {
@Test @Test
...@@ -40,7 +41,7 @@ public class Spr7167Tests { ...@@ -40,7 +41,7 @@ public class Spr7167Tests {
equalTo("post processed by MyPostProcessor")); equalTo("post processed by MyPostProcessor"));
MyConfig config = ctx.getBean(MyConfig.class); MyConfig config = ctx.getBean(MyConfig.class);
assertTrue("Config class was not enhanced", AopUtils.isCglibProxyClass(config.getClass())); assertTrue("Config class was not enhanced", ClassUtils.isCglibProxy(config));
} }
} }
......
...@@ -1083,4 +1083,30 @@ public abstract class ClassUtils { ...@@ -1083,4 +1083,30 @@ public abstract class ClassUtils {
} }
} }
/**
* Check whether the given object is a CGLIB proxy.
* @param object the object to check
* @see org.springframework.aop.support.AopUtils#isCglibProxy(Object)
*/
public static boolean isCglibProxy(Object object) {
return ClassUtils.isCglibProxyClass(object.getClass());
}
/**
* Check whether the specified class is a CGLIB-generated class.
* @param clazz the class to check
*/
public static boolean isCglibProxyClass(Class<?> clazz) {
return (clazz != null && isCglibProxyClassName(clazz.getName()));
}
/**
* Check whether the specified class name is a CGLIB-generated class.
* @param className the class name to check
*/
public static boolean isCglibProxyClassName(String className) {
return (className != null && className.contains(CGLIB_CLASS_SEPARATOR));
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册