use two annotations on one method, and use two different sections to deal with the values in the two annotations respectively. The join point method is as follows:
@CacheFetch(cacheName = CacheManager.CACHE_DATASOURCE_INFO)
@TenantAware(method = OperationMethod.OPERATION, operation = OperationType.GET)
public DataSourceInfo fetchDataSource(String sourceId) {...}
Section method 1:
@Around("within(com.xx.yy.zz..*) && @annotation(fetch)")
public Object fetchFromCache(ProceedingJoinPoint pjp, CacheFetch fetch) throws Throwable {...}
Section method 2:
@Around("isXXX() && @annotation(tenantAware)")
public Object handleTenantAware(ProceedingJoinPoint pjp, TenantAware tenantAware) throws Throwable {...}
The two facet methods are written in two different Aspect classes and implement the Ordered interface. When the pointcut method is executed, the following error is reported:
java.lang.IllegalStateException: Required to bind 2 arguments, but only bound 1 (JoinPointMatch was NOT bound in invocation)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.argBinding(AbstractAspectJAdvice.java:591)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671)
if you remove the comment of one of the methods, the other section method can execute normally. There are very few searches on the Internet, and only people ask about it in the very old version of Spring.
uses version 4.1.6 of Spring, and there is still a problem trying to upgrade to 4.1.9 or 4.3.20.
as far as I understand it, there should be no problem with writing this way, but somehow the error has not been raised, and I am not sure whether it is a bug or a usage problem. I hope someone can help, thank you!