我正在尝试实现一个hibernate拦截来在我的基于Spring的项目中创建一个日志表,我正在努力配置文件。
一切都工作得非常好,但拦截器永远不会消失。
我的拦截器我有@Autowired
我的Dao,因为我需要访问它以在LogTable中保存新输入。所有Daos都有参数中的会话工厂,所以当我尝试添加
<property name="entityInterceptor">
<bean class="com.mypackage.MyLoggingInterceptor"></bean>
</property>
到 sessionFactory bean我有一个循环依赖:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [URL]: Cannot resolve reference to bean 'MyLoggingInterceptor' while setting bean property 'entityInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyLoggingInterceptor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mypackage.UserLogDao com.mypackage.MyLoggingInterceptor.userLogDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserLogDao' defined in URL [URL]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
如果我不添加entityInterceptor
属性,我的程序工作正常,但拦截器永远不会被调用。我该怎么做才能解决这个循环依赖?