I am trying to write an Aspect, trying to implement Pointcut's if() condition but receiving ArrayIndexOutOfBoundsException. here is the code snippet.
@Pointcut("call(* com.aop.Service.activate(..)) && args(iActivate,..) && if()")
public static boolean saveActivate(Activate iActivate) {
return true; //if false @before she not be invoked
};
@Before("saveActivate(iActivate)")
public void saveActivateBefore(JoinPoint ijoinPoint, ActivateInstallmentRequest iActivateInstallmentRequest) {
System.out.println("Log from @before");
}
This code is giving me below exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]: Initialization of bean failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
Can Someone help me what I'm missing here? PS: I have also referred AspectJ.
After having verified that you use Spring AOP, the answer is indeed that both if()
and call()
are not supported, see also the Spring manual section about pointcut designators.
If you want to use those designators, you need to activate AspectJ via LTW (load-time weaving).
A workaround for Spring AOP would be to simply use a regular if
at the beginning of your advice method and, if there are no specific reasons for using call()
, use execution()
instead, which is what most people want anyway. I am not going to elaborate about the difference between call and execution joinpoints here, but you can e.g. consult my answer there for more information.
Update: There are other things which look a little bit strange in your code snippet, but what I explained is the biggest issue for now.