切入点获取表达式不能在XML中工作 [英] Pointcut get expression not working in XML

查看:119
本文介绍了切入点获取表达式不能在XML中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个切入点表达式,用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,以下cflow,if,@ this和@withincode.在Spring AOP解释的切入点表达式中使用这些切入点指示符将导致抛出IllegalArgumentException.

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.

这篇关于切入点获取表达式不能在XML中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆