2010-10-12 3 views
5

Sto cercando di utilizzare HibernateInterceptor come consiglio e sto cercando di autorizzarlo.Autowiring HibernateInterceptor as Advice

Il codice è il seguente,

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

    } 

} 

Di seguito è riportato il mio mapping 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/> 

Quando controllo il hibernateInterceptop, tutto quello che ottiene è NULL: (... Non so perché il suo grado di autowire l'intercettore ibernazione

Tutte le idee? Grazie per il vostro tempo.

Cheers, J

+0

Cosa succede quando si imposta manualmente un'altra proprietà per 'HibernateInterceptor' nella finestra di configurazione di Spring? –

risposta

0

Avete diversi intercettori?

Se si sta utilizzando @Autowired con @Qualifier, suggerisco di utilizzare invece @Resource. È più ... standard.

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

ho avuto problemi con @Autowired e @Qualifier una volta, ma mai con @Resource (@Resource è JSR250, non molla, ma la primavera lo supporta).

Se si dispone solo di un hibernateInterceptor, è possibile utilizzare @Resource con il qualificatore del nome.