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


Java TargetSource.getTarget方法代码示例

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


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

示例1: getCglibProxyTargetObject

import org.springframework.aop.TargetSource; //导入方法依赖的package包/类
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
  String name = proxy.getClass().getName();
  if (name.toLowerCase().contains("cglib")) {
    Method[] methods = proxy.getClass().getDeclaredMethods();
    Method targetSourceMethod = null;
    for (Method method : methods) {
      if (method.getName().endsWith("getTargetSource")) {
        targetSourceMethod = method;
      }
    }
    if (targetSourceMethod != null) {
      targetSourceMethod.setAccessible(true);
      try {
        TargetSource targetSource = (TargetSource) targetSourceMethod.invoke(proxy);
        return targetSource.getTarget();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    } else {
      throw new IllegalStateException(
          "Could not find target source method on proxied object [" + proxy.getClass() + "]");
    }
  }
  return proxy;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:26,代码来源:GrpcAop.java

示例2: get

import org.springframework.aop.TargetSource; //导入方法依赖的package包/类
public ExecutorTemplate get() {
    TargetSource targetSource = (TargetSource) this.beanFactory.getBean("executorTemplateTargetSource");
    try {
        return (ExecutorTemplate) targetSource.getTarget();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:ExecutorTemplateGetter.java

示例3: extractTargetObject

import org.springframework.aop.TargetSource; //导入方法依赖的package包/类
private Object extractTargetObject(Object proxied) {
    try {
        TargetSource springTargetSource = findSpringTargetSource(proxied);
        return springTargetSource.getTarget();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:9,代码来源:CglibHelper.java

示例4: invokeMethod

import org.springframework.aop.TargetSource; //导入方法依赖的package包/类
/**
 * spring注入对象的私有方法调用
 * 
 * @param owner
 *            注入的对象
 * @param methodName
 *            私有方法名
 * @param parameterTypes
 *            私有方法参数类型
 * @param parameters
 *            私有方法参数
 * @return 私有方法返回值
 */
@SuppressWarnings({ "rawtypes" })
public static Object invokeMethod(final Object owner,
        final String methodName, final Class[] parameterTypes,
        final Object[] parameters) throws Exception {

    // get class
    final Class ownerclass = owner.getClass();

    // get property
    try {

        @SuppressWarnings("unchecked")
        final Method getTargetClass = ownerclass
                .getMethod("getTargetSource");
        final TargetSource target = (TargetSource) getTargetClass.invoke(
                owner, new Object[] {});
        final Class targetClass = target.getTargetClass();
        @SuppressWarnings("unchecked")
        final Method method = targetClass.getDeclaredMethod(methodName,
                parameterTypes);

        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        final Object targetInstance = target.getTarget();
        return method.invoke(targetInstance, parameters);

    } catch (NoSuchMethodException e) {

        return invokeMethod(owner, 0, methodName, parameterTypes,
                parameters);
        // e.printStackTrace();
    }
}
 
开发者ID:knightliao,项目名称:disconf,代码行数:48,代码来源:PrivateMethodUtil.java


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