当前位置: 首页 > 知识库问答 >
问题:

AOP/AspectJ未按标准执行的问题

葛磊
2023-03-14

有人知道为什么下面的AOP/AspectJ在示例2,3中不起作用吗?

注:示例1有效。

我的目标是拦截在整个应用程序中触发Hibernate查询的executeUpdate()。Hibernate Query是一个接口,我在代码中看到,我返回的实现类是QueryImpl。这就是我想要针对的类,尽管我也尝试过泛型过滤器。

XML

<aop:config>
    <aop:aspect id="myAspect" ref="aspectBean">

       <!-- EXAMPLE 1: SIMPLE TEST: WORKS OK. 
            I intercept all methods in all my custom classes in "dao" package. -->
        <aop:pointcut id="test1" expression="execution(* myapp.dao.*.*(..))" /> 
        <aop:before pointcut-ref="test1" method="doTest1" /> 

       <!-- EXAMPLE 2: DOESN'T WORK.
            Target everything in Hibernate's Impl package with executeUpdate() function -->         
        <aop:pointcut id="executeUpdate2" expression="execution(* org.hibernate.impl..*..executeUpdate(..))" />
        <aop:before pointcut-ref="executeUpdate2" method="handleExecuteUpdate" /> 

        <!-- EXAMPLE 3: DOESN'T WORK.
            Target QueryImpl specifically -->   
        <aop:pointcut id="executeUpdate3" expression="execution(* org.hibernate.impl.QueryImpl.executeUpdate(..))" /> 
        <aop:before pointcut-ref="executeUpdate3" method="handleExecuteUpdate" /> 

    </aop:aspect>
</aop:config>
<bean id="aspectBean" class="myapp.util.AOPAspect">
</bean>

我知道Hibernate层次结构是正确的。示例#1工作得很好,因此我知道AOP/AspectJ连接正确。外部库遍历是否有不支持AOP/AspectJ的地方?

共有1个答案

淳于祺
2023-03-14

我发现它不起作用,因为我正在处理一个外部JAR(在本例中是Hibernate)。示例1之所以有效,是因为我在自己的代码中。

外部JAR切入点没有简单的解决方案,只有加载时编织是可能的(但我还没有尝试过),

从外部jar拦截方法

 类似资料:
  • 我试图实现一个简单的Spring AOP(v4)示例,使用建议和一个原位切入点表达式,但是没有调用方面方法。我有所有必需的依赖关系(spring-aop、aopalliance和aspectweaver)。我做错了什么? 方面:

  • 很抱歉,我可能会重复这个问题(正如我在许多其他SO网站上看到的那样),但是,我不确定在这一点上还有什么可以尝试的。 我正在尝试设置一个简单的AspectJ Spring应用程序。一旦我有了一个工作示例,我想创建一个公共库,可以通过注释在我的团队中使用,所以我对使用AspectJ非常感兴趣,因为我认为它可以简化我尝试做的很多事情。 下面是我的代码: AspectDemoApplication。课堂—

  • 问题内容: 我的印象是,Spring AOP最适合用于特定于应用程序的任务,例如安全性,日志记录,事务处理等,因为它使用自定义Java5注释作为框架。但是,AspectJ似乎是更友好的设计模式。 谁能强调在Spring应用程序中使用Spring AOP和AspectJ的利弊吗? 问题答案: Spring-AOP优点 它比AspectJ更易于使用,因为你不必使用LTW(加载时编织)或AspectJ编

  • AspectJ意味着它的另一个AOP实现不是基于spring的,如果我们想使用它,那么除了spring之外,我们还需要包括一些第三方JAR。 Spring AOP注释意味着Spring使用AspectJ注释来提供AOP特性。 这些假设公平吗?

  • 本文向大家介绍Spring AOP和AspectJ AOP之间的区别,包括了Spring AOP和AspectJ AOP之间的区别的使用技巧和注意事项,需要的朋友参考一下 序号 键 春季AOP AspectJ AOP 1 基本的 这是AOP技术的简单实现。它只能应用于豆类。 它是Java中AOP技术的完整实现。它可以应用于任何java类。 2 设计模式   它使用代理模式,因此将方面应用于代理对象

  • (1)和(2)两个执行标记的不同含义是什么?