【问题标题】:How to pointcut hibernate when i use spring aop?当我使用spring aop时如何切入休眠?
【发布时间】:2013-01-29 06:17:43
【问题描述】:

我认为作为会话的入口点,但似乎失败了。是否我的配置? 这是我的弹簧配置。

<bean id="aspect" class="org.bigbean.common.aop.DaoAspect" />
<aop:config>
    <aop:aspect ref="aspect">       
        <aop:around pointcut="execution(* org.hibernate.SharedSessionContract.createQuery(java.lang.String))"
            method="aroundAdvice" />
    </aop:aspect>
</aop:config>

跟着我的课

    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
    System.out.println("aroundAdvice");
    String hql = (String) pjp.getArgs()[0];
    if(hql.indexOf("update") > -1){
        StringBuilder sb = new StringBuilder();
        int temp = hql.indexOf("where");
        if(temp > -1){
            sb.append(hql.subSequence(0, temp));
            sb.append(",updateDate = :updateDate ");
            sb.append(hql.substring(temp));
        }else{
            sb.append(",updateDate = :updateDate ");
        }
        hql = sb.toString();
        mark = true;
    }
    Object retVal = pjp.proceed(new Object[] { hql });
    return retVal;
}

【问题讨论】:

    标签: spring aop spring-aop


    【解决方案1】:

    除非您使用load-time weavingcompile-time weaving,否则Spring AOP 是基于代理的。这意味着您只能切入由 Spring 创建的对象(即 Spring bean)。您正在尝试切入一个内部 Hibernate 对象,该对象很可能是使用普通的 new SharedSessionContract() 构造在 hibernate 内部创建的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 2011-03-14
      • 2018-06-13
      • 2010-10-02
      • 1970-01-01
      相关资源
      最近更新 更多