下面是我要创建的方面。我想将两个切入点表达式合并为一个。我已经看到这可以使用带注释的切入点来完成,但是 xml 中的相同语法失败了。谁能帮帮我?
<aspects>
<concrete-aspect name="com.logger.aspect.InjectionLoggerImpl"
extends="com.logger.aspect.InjectionLogger">
<pointcut name="loggingInterceptor"
expression="execution(* com.*..*.next(..)) || execution(* com.*..*.read(..))"/>
<pointcut name="methExecInterceptor="some expression"/>
</concrete-aspect>
</aspects>
提前致谢
最佳答案
在 xml 中使用 Spring 2.0.x 是不可能的:
XML style is more limited in what in can express than the @AspectJ style: only the "singleton" aspect instantiation model is supported, and it is not possible to combine named pointcuts declared in XML
6.4.2. @AspectJ or XML for Spring AOP
但是在 Spring 3.0.x 中是可能的:
When combining pointcut sub-expressions, '&&' is awkward within an XML document, and so the keywords 'and', 'or' and 'not' can be used in place of '&&', '||' and '!' respectively. For example, the previous pointcut may be better written as:
<aop:config>
<aop:aspect id="myAspect" ref="aBean">
<aop:pointcut id="businessService"
expression="execution(* com.xyz.myapp.service.*.*(..)) and this(service)"/>
<aop:before pointcut-ref="businessService" method="monitor"/>
...
</aop:aspect>
</aop:config>
关于java - 在没有 Spring 的情况下在 aop.xml 中组合 AOP 切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7756690/