本文整理汇总了Java中org.springframework.aop.framework.AopProxyUtils类的典型用法代码示例。如果您正苦于以下问题:Java AopProxyUtils类的具体用法?Java AopProxyUtils怎么用?Java AopProxyUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AopProxyUtils类属于org.springframework.aop.framework包,在下文中一共展示了AopProxyUtils类的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: testFooService
import org.springframework.aop.framework.AopProxyUtils; //导入依赖的package包/类
@Test
public void testFooService() {
assertNotEquals(fooService.getClass(), FooServiceImpl.class);
assertTrue(AopUtils.isAopProxy(fooService));
assertTrue(AopUtils.isCglibProxy(fooService));
assertEquals(AopProxyUtils.ultimateTargetClass(fooService), FooServiceImpl.class);
assertEquals(AopTestUtils.getTargetObject(fooService).getClass(), FooServiceImpl.class);
assertEquals(AopTestUtils.getUltimateTargetObject(fooService).getClass(), FooServiceImpl.class);
assertEquals(fooService.incrementAndGet(), 0);
assertEquals(fooService.incrementAndGet(), 0);
}
示例15: testFooService
import org.springframework.aop.framework.AopProxyUtils; //导入依赖的package包/类
@Test
public void testFooService() {
assertNotEquals(fooService.getClass(), FooServiceImpl.class);
assertTrue(AopUtils.isAopProxy(fooService));
assertTrue(AopUtils.isCglibProxy(fooService));
assertEquals(AopProxyUtils.ultimateTargetClass(fooService), FooServiceImpl.class);
assertEquals(AopTestUtils.getTargetObject(fooService).getClass(), FooServiceImpl.class);
assertEquals(AopTestUtils.getUltimateTargetObject(fooService).getClass(), FooServiceImpl.class);
assertEquals(fooService.incrementAndGet(), 0);
assertEquals(fooService.incrementAndGet(), 0);
verify(fooAspect, times(2)).changeIncrementAndGet(any());
}