我有2个JAR文件,比如A.jar和B.jar,A.jar包含一个Spring XML,A.xml,它定义了与事务相关的东西。
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="lookUpDataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<tx:method name="readAll" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="FooBarOperation"
expression="execution(* com.foo.bar.service.*ServiceInterface.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="FooBarOperation" />
</aop:config>
我在A.jar,com.foo.bar.service.AlphaServiceInterface中编写了一个服务,它使用Hibernate SQL执行数据库事务。当我使用A.jar中的JUnit测试这个服务时,一切都很好,代理是由Spring创建的,我可以运行服务调用。现在,我将Spring XML文件导入另一个Spring XML文件,B.xml,使用
放在B.jar中<import resource="classpath:/META-INF/spring/A.xml"/>
我在B.jar中编写完全相同的junit测试并尝试测试它,不创建事务上下文并运行以下异常:org.hibernate.HibernateException:如果没有活动事务,createSQLQuery无效
请注意,此问题与Spring Aspect not executed when defined in other JAR。
有关答案 0 :(得分:0)
我发现这种情况正在发生,因为我的hibernate.cfg.xml中有以下内容:
<property name="current_session_context_class">thread</property>
在删除上面的工作正常后,我还没有找出agove是如何造成这个问题的。