Pointcut get expression not working in XML

2019-09-16 11:24发布

I have a pointcut expression which is working fine when written in java but when written in xml gives error. Since my aspect is written in one project and it's jar is available in other project I have to provide it's mapping in the XML in other projects using the same aspect in JAR.
In Java:

@Pointcut("get(java.lang.String com.air.ghl..*) and @annotation(value)")
public void isDynamicValue(DynamicValue dynamicValue) {}

@Around("isDynamicValue(dynamicValue)")
public Object getDynamicString(DynamicValue dynamicValue, ProceedingJoinPoint thisJoinPoint) throws Throwable {
    System.out.println(thisJoinPoint);
    System.out.println("    " + dynamicValue);
    return thisJoinPoint.proceed();
}

In XML:

<bean id="dynamicValueAspect" class="com.air.ghl.util.DynamicValueAspect"/>
<aop:aspect id="dynamicValue" ref="dynamicValueAspect">
    <aop:pointcut id="dynamicValueStringPointCut" expression="get(java.lang.String com.air.ghl..*) and @annotation(value)"/>
    <aop:around method="getDynamicString" pointcut-ref="dynamicValueStringPointCut"/>
 </aop:aspect

Error while server up:

Caused by: org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException: Pointcut expression 'get(java.lang.String com.air.ghl..*) && @annotation(value)' contains unsupported pointcut primitive 'get'
at org.aspectj.weaver.tools.PointcutParser.validateKindedPointcut(PointcutParser.java:522)
at org.aspectj.weaver.tools.PointcutParser.validateAgainstSupportedPrimitives(PointcutParser.java:437)
at org.aspectj.weaver.tools.PointcutParser.validateAgainstSupportedPrimitives(PointcutParser.java:412)
at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:311)
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:294)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:208)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:194)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:183)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getMethodMatcher(AspectJExpressionPointcut.java:169)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.buildSafePointcut(AbstractAspectJAdvice.java:187)
at org.springframework.aop.aspectj.AspectJPointcutAdvisor.<init>(AspectJPointcutAdvisor.java:51)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)

Thanks. :)

1条回答
够拽才男人
2楼-- · 2019-09-16 12:09

Obviously in your code you were using full-fledged AspectJ (maybe via LTW, load-time weaving). Then you are fine with get() pointcuts. The XML variant is obviously Spring AOP and as the error message says, as an "AOP lite" framework it does not support get among several other AspectJ pointcuts, see Spring manual, chapter on AOP, section Supported Pointcut Designators. It says:

The full AspectJ pointcut language supports additional pointcut designators that are not supported in Spring. These are: call, get, set, preinitialization, staticinitialization, initialization, handler, adviceexecution, withincode, cflow, cflowbelow, if, @this, and @withincode. Use of these pointcut designators in pointcut expressions interpreted by Spring AOP will result in an IllegalArgumentException being thrown.

查看更多
登录 后发表回答