use of org.springframework.aop.framework.Advised in project spring-data-commons by spring-projects.
the class ProxyProjectionFactoryUnitTests method invokesDefaultMethodOnProxy.
// DATACMNS-655
@Test
public void invokesDefaultMethodOnProxy() {
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
Advised advised = (Advised) ReflectionTestUtils.getField(Proxy.getInvocationHandler(excerpt), "advised");
Advisor[] advisors = advised.getAdvisors();
assertThat(advisors.length).isGreaterThan(0);
assertThat(advisors[0].getAdvice()).isInstanceOf(DefaultMethodInvokingMethodInterceptor.class);
}
use of org.springframework.aop.framework.Advised in project spring-data-commons by spring-projects.
the class DomainClassConverterUnitTests method convertsStringToUserCorrectly.
@Test
public void convertsStringToUserCorrectly() throws Exception {
ApplicationContext context = initContextWithRepo();
converter.setApplicationContext(context);
doReturn(1L).when(service).convert(any(), eq(Long.class));
converter.convert("1", STRING_TYPE, USER_TYPE);
UserRepository bean = context.getBean(UserRepository.class);
UserRepository repo = (UserRepository) ((Advised) bean).getTargetSource().getTarget();
verify(repo, times(1)).findById(1L);
}
use of org.springframework.aop.framework.Advised in project spring-cloud-stream by spring-cloud.
the class StreamListenerAnnotationBeanPostProcessor method checkProxy.
private Method checkProxy(Method methodArg, Object bean) {
Method method = methodArg;
if (AopUtils.isJdkDynamicProxy(bean)) {
try {
// Found a @StreamListener method on the target class for this JDK proxy
// ->
// is it also present on the proxy itself?
method = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
Class<?>[] proxiedInterfaces = ((Advised) bean).getProxiedInterfaces();
for (Class<?> iface : proxiedInterfaces) {
try {
method = iface.getMethod(method.getName(), method.getParameterTypes());
break;
} catch (NoSuchMethodException noMethod) {
}
}
} catch (SecurityException ex) {
ReflectionUtils.handleReflectionException(ex);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException(String.format("@StreamListener method '%s' found on bean target class '%s', " + "but not found in any interface(s) for bean JDK proxy. Either " + "pull the method up to an interface or switch to subclass (CGLIB) " + "proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'", method.getName(), method.getDeclaringClass().getSimpleName()), ex);
}
}
return method;
}
use of org.springframework.aop.framework.Advised in project openmrs-core by openmrs.
the class ServiceContext method addAdvisor.
/**
* @param cls
* @param advisor
*/
public void addAdvisor(Class cls, Advisor advisor) {
Advised advisedService = (Advised) services.get(cls);
if (advisedService.indexOf(advisor) < 0) {
advisedService.addAdvisor(advisor);
}
addedAdvisors.computeIfAbsent(cls, k -> new HashSet<>());
getAddedAdvisors(cls).add(advisor);
}
use of org.springframework.aop.framework.Advised in project openmrs-core by openmrs.
the class ServiceContext method removeAdvice.
/**
* @param cls
* @param advice
*/
public void removeAdvice(Class cls, Advice advice) {
Advised advisedService = (Advised) services.get(cls);
advisedService.removeAdvice(advice);
getAddedAdvice(cls).remove(advice);
}
Aggregations