當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。