使用spring aop时如何切入点休眠? [英] How to pointcut hibernate when i use spring aop?

查看:36
本文介绍了使用spring aop时如何切入点休眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I think as an entry point to the session, but seems to have failed. Whether my configuration? Here is my spring config.

<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>

follow is my class

follow is my class

    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 创建的对象(即 Spring bean)中使用切入点.您正在尝试切入一个内部 Hibernate 对象,该对象很可能是使用普通的 new SharedSessionContract() 构造在 hibernate 内部创建的.

Unless you are using load-time weaving or compile-time weaving, Spring AOP is proxy-based. This means you can only pointcut in objects created by Spring (i.e. Spring beans). You are trying to pointcut an internal Hibernate object which is most likely created inside hibernate using the normal new SharedSessionContract() construct.

这篇关于使用spring aop时如何切入点休眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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