【发布时间】:2010-10-12 07:04:39
【问题描述】:
我正在尝试使用 HibernateInterceptor 作为建议,我正在尝试自动装配它。
代码如下,
@Aspect
public class InterceptorAdvice{
private HibernateInterceptor hibernateInterceptor;
@Autowired
public void setHibernateInterceptor(@Qualifier("hibernateInterceptor") HibernateInterceptor hibernateInterceptor) {
this.hibernateInterceptor = hibernateInterceptor;
}
@Around("execution(* *..*.dao..*.*(..))")
public Object interceptCall(ProceedingJoinPoint joinPoint) throws Exception {
Object obj = null;
try{
.......
}catch(Exception e){
e.printStackTrace();
}
return obj;
}
}
以下是我的XML映射,
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor" autowire="byName">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!--To enable AspectJ AOP-->
<aop:aspectj-autoproxy/>
<!--Your advice-->
<bean class="com.web.aop.InterceptorAdvice"/>
<!--Looks for any annotated Spring bean in com.app.dao package-->
<context:component-scan base-package="com.web.dao"/>
<!--Enables @Autowired annotation-->
<context:annotation-config/>
当我检查 hibernateInterceptop 时,我得到的只是 NULL :(...不知道为什么它无法自动连接休眠拦截器
有什么想法吗?感谢您的宝贵时间。
干杯, J
【问题讨论】:
-
当您在 Spring 配置中手动为
HibernateInterceptor设置另一个属性时会发生什么?
标签: java hibernate spring spring-aop