java - 在没有 Spring 的情况下在 aop.xml 中组合 AOP 切入点

标签 java spring aop

下面是我要创建的方面。我想将两个切入点表达式合并为一个。我已经看到这可以使用带注释的切入点来完成,但是 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>

Spring 3 aop

关于java - 在没有 Spring 的情况下在 aop.xml 中组合 AOP 切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7756690/

相关文章:

java - 如何使用 AspectJ 和 log4j 原始日志行号?

java - Aspectj 中的 LTW 问题

java - AnnotationAwareAspectJAutoProxyCreator 仅适用于 Java 1.5 及更高版本

java - 使用 maven 和 eclipse 与 OSGi 合并 2 个项目

java - GWT Web 应用程序与动态加载类的系统类路径

java - java小程序中的JComboBox和JTable

java - typeMismatch.java.util.List 尝试设置列表时

java - 使用 Bean Utils 填充 POJO 时为字段设置默认值

java - 一个测试用例的测试数据反射(reflect)在另一个测试用例中

java - 当用户在 spring-security 中注销时从 session 中删除用户登录凭据