本文介绍了当我使用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>
跟随我上课
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时如何切入冬眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!