当前位置: 首页>>代码示例>>Java>>正文


Java AopUtils.isAopProxy方法代码示例

本文整理汇总了Java中org.springframework.aop.support.AopUtils.isAopProxy方法的典型用法代码示例。如果您正苦于以下问题:Java AopUtils.isAopProxy方法的具体用法?Java AopUtils.isAopProxy怎么用?Java AopUtils.isAopProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.aop.support.AopUtils的用法示例。


在下文中一共展示了AopUtils.isAopProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTargetObject

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private static Object getTargetObject(Object proxy) {
	try {
		if (!AopUtils.isAopProxy(proxy)) {// 不是代理对象
			return proxy;
		}
		if (AopUtils.isCglibProxy(proxy)) {// cglib代理对象
			return getCglibProxyTargetObject(proxy);
		}
		if (AopUtils.isJdkDynamicProxy(proxy)) {// jdk动态代理
			return getJdkDynamicProxyTargetObject(proxy);
		}
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:17,代码来源:BeanContextUtil.java

示例2: getCglibProxyTargetObject

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
	Field field = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
       field.setAccessible(true);
       Object dynamicAdvisedInterceptor = field.get(proxy);
       
       Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
       advised.setAccessible(true);
       
       Object target = ((AdvisedSupport)advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();

       if(!AopUtils.isAopProxy(target)){
		throw new EndRecursionException(target);
	}
	getCglibProxyTargetObject(target);
       return null;
}
 
开发者ID:Yanweichen,项目名称:SimpleProcessControl,代码行数:17,代码来源:AopTargetUtils.java

示例3: buildScheduledRunnable

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
/**
 * 封装ScheduledMethodRunnable对象
 */
private static ScheduledMethodRunnable buildScheduledRunnable(Object bean, String targetMethod, String params, String extKeySuffix, boolean onlyOne) throws Exception {

    Assert.notNull(bean, "target object must not be null");
    Assert.hasLength(targetMethod, "Method name must not be empty");

    Method method;
    ScheduledMethodRunnable scheduledMethodRunnable;
    Class<?> clazz;
    if (AopUtils.isAopProxy(bean)) {
        clazz = AopProxyUtils.ultimateTargetClass(bean);
    } else {
        clazz = bean.getClass();
    }
    if (params != null) {
        method = ReflectionUtils.findMethod(clazz, targetMethod, String.class);
    } else {
        method = ReflectionUtils.findMethod(clazz, targetMethod);
    }
    Assert.notNull(method, "can not find method named " + targetMethod);
    scheduledMethodRunnable = new ScheduledMethodRunnable(bean, method, params, extKeySuffix, onlyOne);
    return scheduledMethodRunnable;
}
 
开发者ID:liuht777,项目名称:uncode-scheduler,代码行数:26,代码来源:DynamicTaskManager.java

示例4: unwrapProxy

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
public static <T> T unwrapProxy(final Class<T> clazz, final Object proxy) {
    Object target = proxy;

    if (AopUtils.isAopProxy(proxy) && proxy instanceof Advised) {
        try {
            target = Advised.class.cast(proxy).getTargetSource().getTarget();
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }

    if (target != null && clazz.isAssignableFrom(target.getClass())) {
        return clazz.cast(target);
    }

    throw new IllegalArgumentException("proxy object does not represent given class: " + clazz.getSimpleName());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:18,代码来源:TestUtils.java

示例5: assertTxProxying

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private void assertTxProxying(AnnotationConfigApplicationContext ctx) {
	FooRepository repo = ctx.getBean(FooRepository.class);

	boolean isTxProxy = false;
	if (AopUtils.isAopProxy(repo)) {
		for (Advisor advisor : ((Advised)repo).getAdvisors()) {
			if (advisor instanceof BeanFactoryTransactionAttributeSourceAdvisor) {
				isTxProxy = true;
				break;
			}
		}
	}
	assertTrue("FooRepository is not a TX proxy", isTxProxy);

	// trigger a transaction
	repo.findAll();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:EnableTransactionManagementIntegrationTests.java

示例6: isMultipleProxy

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
/**
 * 是否代理了多次
 * see http://jinnianshilongnian.iteye.com/blog/1894465
 * @param proxy
 * @return
 */
public static boolean isMultipleProxy(Object proxy) {
    try {
        ProxyFactory proxyFactory = null;
        if(AopUtils.isJdkDynamicProxy(proxy)) {
            proxyFactory = findJdkDynamicProxyFactory(proxy);
        }
        if(AopUtils.isCglibProxy(proxy)) {
            proxyFactory = findCglibProxyFactory(proxy);
        }
        TargetSource targetSource = (TargetSource) ReflectionUtils.getField(ProxyFactory_targetSource_FIELD, proxyFactory);
        return AopUtils.isAopProxy(targetSource.getTarget());
    } catch (Exception e) {
        throw new IllegalArgumentException("proxy args maybe not proxy with cglib or jdk dynamic proxy. this method not support", e);
    }
}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:22,代码来源:AopProxyUtils.java

示例7: removeAdvisor

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private static void removeAdvisor(Object proxy, Class<? extends Advice> adviceClass) {
    if(!AopUtils.isAopProxy(proxy)) {
        return;
    }
    ProxyFactory proxyFactory = null;
    if(AopUtils.isJdkDynamicProxy(proxy)) {
        proxyFactory = findJdkDynamicProxyFactory(proxy);
    }
    if(AopUtils.isCglibProxy(proxy)) {
        proxyFactory = findCglibProxyFactory(proxy);
    }

    Advisor[] advisors = proxyFactory.getAdvisors();

    if(advisors == null || advisors.length == 0) {
        return;
    }

    for(Advisor advisor : advisors) {
        if(adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
            proxyFactory.removeAdvisor(advisor);
            break;
        }
    }
}
 
开发者ID:leiyong0326,项目名称:phone,代码行数:26,代码来源:AopProxyUtils.java

示例8: proxyToObject

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
public static Object proxyToObject(Object object) {
	Object result = object;
	if (AopUtils.isAopProxy(object)) {
		try {
			LOGGER.debug("{} spring proxy, get real object", object);
			result = ((Advised) object).getTargetSource().getTarget();
			LOGGER.debug("Real Object: {}", object);
		} catch (Exception e) {
			LOGGER.error("Problemas al obtener el controller: {}", object, e);
		}
	}
	return result;
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:14,代码来源:ReflectionUtils.java

示例9: getServiceClass

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
@Override
protected Class getServiceClass(T ref) {
    if (AopUtils.isAopProxy(ref)) {
        return AopUtils.getTargetClass(ref);
    }
    return super.getServiceClass(ref);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:8,代码来源:ServiceBean.java

示例10: getTarget

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private Object getTarget(Object proxy){
	if(!AopUtils.isAopProxy(proxy)) {
		return proxy;//不是代理对象
	}
	try {
		if(AopUtils.isJdkDynamicProxy(proxy)) {
				return getJdkDynamicProxyTargetObject(proxy);
		} else { //cglib
			return getCglibProxyTargetObject(proxy);
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:15,代码来源:ActionServletHandler.java

示例11: getJdkDynamicProxyTargetObject

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
	Field field = proxy.getClass().getSuperclass().getDeclaredField("h");
       field.setAccessible(true);
       AopProxy aopProxy = (AopProxy) field.get(proxy);
       
       Field advised = aopProxy.getClass().getDeclaredField("advised");
       advised.setAccessible(true);
       
       Object target = ((AdvisedSupport)advised.get(aopProxy)).getTargetSource().getTarget();
	if(!AopUtils.isAopProxy(target)){
		throw new EndRecursionException(target);
	}
	getJdkDynamicProxyTargetObject(target);
       return null;
}
 
开发者ID:Yanweichen,项目名称:SimpleProcessControl,代码行数:16,代码来源:AopTargetUtils.java

示例12: setField

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
public void setField(final Object target, final String name, final Object value) {

        // check if the object is a proxy object
        if (AopUtils.isAopProxy(target) && target instanceof Advised) {
            try {
                ReflectionTestUtils.setField(((Advised) target).getTargetSource().getTarget(), name, value);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            ReflectionTestUtils.setField(target, name, value);
        }
    }
 
开发者ID:eclipse,项目名称:keti,代码行数:14,代码来源:TestUtils.java

示例13: getTarget

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
/** 
 * 获取 目标对象 
 * @param proxy 代理对象 
 * @return  
 * @throws Exception 
 */  
public static Object getTarget(Object proxy) throws Exception {  
    if(!AopUtils.isAopProxy(proxy)) {  
        return proxy;//不是代理对象  
    }  
    if(AopUtils.isJdkDynamicProxy(proxy)) {  
        return getJdkDynamicProxyTargetObject(proxy);  
    } else { 
        return getCglibProxyTargetObject(proxy);  
    }  
      
}
 
开发者ID:devpage,项目名称:fastdfs-quickstart,代码行数:18,代码来源:AopTargetUtils.java

示例14: injectDependencies

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
@Override
protected void injectDependencies(TestContext testContext) throws Exception {
    super.injectDependencies(testContext);
    /**
     * 获取测试类 & fields
     */
    Object bean = testContext.getTestInstance();
    List<Field> fields = getDeclaredFields(bean);
    if (CollectionUtils.isEmpty(fields)) {
        return;
    }
    /**
     * 如果测试类中, 被测试对象含有mockito的@InjectMocks注解,且 被测试对象被事务拦截器拦截 则 用原始对象代替
     */
    for (Field field : fields) {
        InjectMocks injectMocks = field.getAnnotation(InjectMocks.class);
        if (injectMocks == null) {
            continue;
        }
        field.setAccessible(true);
        Object proxy = field.get(bean);
        if (AopUtils.isAopProxy(proxy)) {
            // 替换对象
            Object target = ((Advised) proxy).getTargetSource().getTarget();
            field.set(bean, target);
        }
    }
}
 
开发者ID:warlock-china,项目名称:wisp,代码行数:29,代码来源:UnitTestDependencyInjectionTestExecutionListener.java

示例15: loadSshdShellCommands

import org.springframework.aop.support.AopUtils; //导入方法依赖的package包/类
private void loadSshdShellCommands(Map<String, Map<String, CommandExecutableDetails>> sshdShellCommandsMap,
        Object obj) throws SecurityException, NoSuchMethodException, InterruptedException {
    Class<?> clazz = AopUtils.isAopProxy(obj) ? AopUtils.getTargetClass(obj) : obj.getClass();
    SshdShellCommand annotation = AnnotationUtils.findAnnotation(clazz, SshdShellCommand.class);
    Map<String, CommandExecutableDetails> map = getSupplierMap(annotation, sshdShellCommandsMap);
    loadSshdShellCommandSuppliers(clazz, annotation, map, obj);
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:8,代码来源:SshdShellAutoConfiguration.java


注:本文中的org.springframework.aop.support.AopUtils.isAopProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。