Autowiring HibernateInterceptor as a tip

I am trying to use HibernateInterceptor as a tip, and I am trying to auto-install it.

The code is as follows:

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

    }

}

Below is my XML mapping,

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

When I check the hibernateInterceptop, all I get is NULL: (... Not sure why it wasn’t able to auto-detect the sleep interceptor

Any ideas? Thank you for your time.

Cheers j

+5
source share
1 answer

Do you have several interceptors?

If you use @Autowired with @Qualifier, I would suggest that you use @Resource instead. This is more ... standard.

@Resource(name="hibernateInterceptor")
public void setHibernateInterceptor(HibernateInterceptor value) {
  hibernateInterceptor = value;
}

@Autowired @Qualifier , @Resource (@Resource JSR250, Spring, Spring ).

hibernateInterceptor, @Resource .

0

All Articles