Spring AOP uses multiple bound Around section methods on a single join point (JoinPoint). (advice) Times error

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!

Sep.16,2021

if the Ordered interface is implemented, its default value is as follows.

public int getOrder() {
    return Ordered.HIGHEST_PRECEDENCE + 1;
}

if there are two Ordered, the interceptor may not be able to determine which one takes precedence. When @ Order, you can specify an int-type value attribute. The smaller the attribute value, the higher the priority.
for example:

@Aspect
@Order(1)
public class AspectFirst {
}

@Aspect
@Order(2)
public class AspectSecond {
}

you try


your problem is that you use the form of annotations @ annotation (tenantAware) ") to get parameters. There is no problem in the case of only one cut, but aspect nesting is not good. You can use the traditional way to get this tenantAware .


dig, follow the source code, it is easy to find that after the two specify different @ Order, the order of the agents is clearly distinguished. However, the method after the proxy is not annotated, resulting in a mismatch in the number of parameters in the second section.

  • two improvements:

    1. the matching of pointcuts does not use @ annotation, to match to pointcuts and uses reflection to obtain annotation content;
    2. uses only one aspect annotation on a method (these annotations are preferably maintained in a separate class for aspect sorting)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3261b-2bdff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3261b-2bdff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?