本文整理汇总了Java中org.springframework.aop.framework.AopProxyUtils.ultimateTargetClass方法的典型用法代码示例。如果您正苦于以下问题:Java AopProxyUtils.ultimateTargetClass方法的具体用法?Java AopProxyUtils.ultimateTargetClass怎么用?Java AopProxyUtils.ultimateTargetClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.aop.framework.AopProxyUtils
的用法示例。
在下文中一共展示了AopProxyUtils.ultimateTargetClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpecificmethod
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
private Method getSpecificmethod(ProceedingJoinPoint pjp) {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
// The method may be on an interface, but we need attributes from the
// target class. If the target class is null, the method will be
// unchanged.
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(pjp.getTarget());
if (targetClass == null && pjp.getTarget() != null) {
targetClass = pjp.getTarget().getClass();
}
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
// If we are dealing with method with generic parameters, find the
// original method.
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
return specificMethod;
}
示例2: buildScheduledRunnable
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的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;
}
示例3: _buildScheduledRunnable
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
private static ScheduledMethodRunnable _buildScheduledRunnable(Object bean, String targetMethod, String params) 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);
return scheduledMethodRunnable;
}
示例4: getSpecificmethod
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
/**
* Finds out the most specific method when the execution reference is an
* interface or a method with generic parameters
*
* @param pjp
* @return
*/
private Method getSpecificmethod(ProceedingJoinPoint pjp) {
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
Method method = methodSignature.getMethod();
// The method may be on an interface, but we need attributes from the
// target class. If the target class is null, the method will be
// unchanged.
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(pjp.getTarget());
if (targetClass == null && pjp.getTarget() != null) {
targetClass = pjp.getTarget().getClass();
}
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
// If we are dealing with method with generic parameters, find the
// original method.
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
return specificMethod;
}
示例5: postProcessAfterInitialization
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
// need the target class, not the Spring proxied one
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean);
// for each method in the bean
for(Method method : targetClass.getMethods()) {
if(method.isAnnotationPresent(Subscribe.class)) {
log.debug("Register bean {} ({}) containing method {} to EventBus", beanName, bean.getClass().getName(),
method.getName());
// register it with the event bus
eventBus.register(bean);
return bean; // we only need to register once
}
}
return bean;
}
示例6: getTargetClass
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
private Class<?> getTargetClass(Object target) {
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
if (targetClass == null && target != null) {
targetClass = target.getClass();
}
return targetClass;
}
示例7: getTargetClass
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
private Class<?> getTargetClass(Object target) {
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
if (targetClass == null && target != null) {
targetClass = target.getClass();
}
return targetClass;
}
示例8: testRootVars
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
public void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
assertSame(r1, service.rootVars(key));
Cache cache = cm.getCache("testCache");
// assert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
assertNotNull(cache.get(expectedKey));
}
示例9: getMostSpecificMethod
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
public Method getMostSpecificMethod() {
if (this.mostSpecificMethod != null) {
return this.mostSpecificMethod;
}
else if (AopUtils.isAopProxy(this.bean)) {
Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean);
return AopUtils.getMostSpecificMethod(getMethod(), target);
}
else {
return getMethod();
}
}
示例10: getTargetClass
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
private Class<?> getTargetClass(Object target) {
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
if (targetClass == null && target != null) {
targetClass = target.getClass();
}
return targetClass;
}
示例11: getMethodAnnotation
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
private <T extends Annotation> MethodAnnotation<T> getMethodAnnotation(MethodInvocation invocation,
Class<T> annotationClass) {
Method method = invocation.getMethod();
T annotation = method.getAnnotation(annotationClass);
//Try to read the class level annotation if the interface is not found
if (annotation != null) {
return new MethodAnnotation(method, annotation);
}
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(
((ReflectiveMethodInvocation) invocation).getProxy());
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
annotation = specificMethod.getAnnotation(annotationClass);
return new MethodAnnotation(specificMethod, annotation);
}
示例12: synchronizeInvocation
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
@Around("synchronizePointcut()")
public Object synchronizeInvocation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature();
Method method = methodSignature.getMethod();
Object target = proceedingJoinPoint.getTarget();
Object[] args = proceedingJoinPoint.getArgs();
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
Synchronized annotation = getAnnotation(targetClass, method);
Validate.notNull(annotation, "Could not find @Synchronized annotation!");
Lock lock = getLock(targetClass, method, args, annotation);
if (lock == null) {
logger.debug("No lock obtained for call [{}] on targetClass [{}] - proceeding without synchronization on " +
"thread {}", new Object[]{method.getName(), targetClass.getName(), Thread.currentThread().getId()});
return proceedingJoinPoint.proceed();
} else {
try {
logger.debug("Lock obtained for call [{}] on targetClass [{}] - proceeding with synchronization on thread {}",
new Object[]{method.getName(), targetClass.getName(), Thread.currentThread().getId()});
lock.lock();
return proceedingJoinPoint.proceed();
} finally {
lock.unlock();
lockService.returnLock(lock);
}
}
}
示例13: testRootVars
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
public void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
assertSame(r1, service.rootVars(key));
Cache cache = cm.getCache("default");
// assert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
assertNotNull(cache.get(expectedKey));
}
示例14: execute
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
protected Object execute(Invoker invoker, Object target, Method method, Object[] args) {
// check whether aspect is enabled
// to cope with cases where the AJ is pulled in automatically
if (!this.initialized) {
return invoker.invoke();
}
// get backing class
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
if (targetClass == null && target != null) {
targetClass = target.getClass();
}
Collection<CacheOperation> cacheOp = getCacheOperationSource().getCacheOperations(method, targetClass);
// analyze caching information
if (!CollectionUtils.isEmpty(cacheOp)) {
Map<String, Collection<CacheOperationContext>> ops = createOperationContext(cacheOp, method, args, target, targetClass);
// start with evictions
inspectBeforeCacheEvicts(ops.get(EVICT));
// follow up with cacheable
CacheStatus status = inspectCacheables(ops.get(CACHEABLE));
Object retVal;
Map<CacheOperationContext, Object> updates = inspectCacheUpdates(ops.get(UPDATE));
if (status != null) {
if (status.updateRequired) {
updates.putAll(status.cacheUpdates);
}
// return cached object
else {
return status.retVal;
}
}
retVal = invoker.invoke();
inspectAfterCacheEvicts(ops.get(EVICT), retVal);
if (!updates.isEmpty()) {
update(updates, retVal);
}
return retVal;
}
return invoker.invoke();
}
示例15: testRepository
import org.springframework.aop.framework.AopProxyUtils; //导入方法依赖的package包/类
@Test
public void testRepository() throws Exception {
this.context = new AnnotationConfigApplicationContext(SimpleTaskConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
TaskRepository taskRepository = this.context.getBean(TaskRepository.class);
assertNotNull("testRepository should not be null", taskRepository);
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskRepository);
assertEquals(targetClass, SimpleTaskRepository.class);
}