本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}