问题描述
我有一个切入点表达式,它在用 java 编写时工作正常,但在用 xml 编写时会出错.由于我的方面是在一个项目中编写的,而它的 jar 在其他项目中可用,因此我必须在其他项目中使用 JAR 中的相同方面在 XML 中提供它的映射.
在 Java 中:
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();
}
在 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)
谢谢.:)
推荐答案
很明显,您在代码中使用了成熟的 AspectJ(可能通过 LTW,加载时编织).然后你就可以使用 get()
切入点.XML 变体显然是 Spring AOP,正如错误消息所说,作为AOP lite"框架,它不支持 get
以及其他几个 AspectJ 切入点,请参阅 Spring 手册,AOP 章节,支持的切入点指示符.它说:
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:
完整的 AspectJ 切入点语言支持 Spring 不支持的其他切入点指示符.它们是:调用、获取、设置、预初始化、静态初始化、初始化、处理程序、建议执行、代码内、cflow、cflowbelow、if、@this 和 @withincode.在 Spring AOP 解释的切入点表达式中使用这些切入点指示符将导致抛出 IllegalArgumentException.
这篇关于切入点获取表达式在 XML 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!