我有一个切入点表达式,当用java编写时工作正常但是用xml编写时会出错。由于我的方面是在一个项目中编写的,并且它的jar在其他项目中可用,我必须使用JAR中的相同方面在其他项目中的XML中提供它的映射。
在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();
}
在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
服务器启动时出错:
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)
感谢。 :)
答案 0 :(得分:0)
显然,在您的代码中,您使用的是成熟的AspectJ(可能是通过LTW,加载时编织)。那么你可以使用get()
切入点。 XML变体显然是Spring AOP,正如错误消息所说,作为&#34; AOP lite&#34;它不支持其他几个AspectJ切入点中的get
框架,请参阅Spring手册,AOP章节,Supported Pointcut Designators部分。它说:
完整的AspectJ切入点语言支持Spring中不支持的其他切入点指示符。它们是:call,get,set,preinitialization,staticinitialization,initialization,handler,adviceexecution,withincode,cflow,cflowbelow,if,@ this和@withincode。在Spring AOP解释的切入点表达式中使用这些切入点指示符将导致抛出IllegalArgumentException。