简体   繁体   English

春季测试和交易管理

[英]spring test and transaction management

I'm extremely new to spring testing. 我是春季测试的新手。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContextTest.xml")
public class joinTest {
@Mock
@Autowired
private AccountDAO DAO;

@Test
public void testMethod()
{
    (DAO).getJoin();
}

}

The test complains about the transactionManager that I have in my applicationContextTest. 该测试抱怨我的applicationContextTest中具有transactionManager。 Obviously I'm running this out of a container. 显然我正在用容器运行它。 I don't really know how to deal with transactions in a Spring Test context. 我真的不知道如何在Spring Test上下文中处理事务。

<context:component-scan base-package="com.abstinence.Logic"/>
<context:annotation-config/>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql://xx.xx.xx.xx/testdb"/>
    <property name="username" value="SA"/>
    <property name="password" value=""/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="com.abstinence.Logic"/>
    <property name="hibernateProperties">
        <props>
            <prop key ="dialect">org.hibernate.dialect.HSQLDialect</prop>
        </props>
    </property>
</bean>

<tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="hibernateDAOOperation" expression="execution(* com.abstinence.Logic.AccountDAO.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="hibernateDAOOperation"/>
</aop:config>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

The exact error I get is this: 我得到的确切错误是这样的:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDAO' defined in file [/home/user/NetBeansProjects/WebAbstinenceMaven/target/classes/com/abstinence/Logic/AccountDAO.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContextTest.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getConnectionProvider()Lorg/hibernate/service/jdbc/connections/spi/ConnectionProvider;

I've been confused for a few days trying to figure this out. 我已经迷惑了几天试图解决这个问题。 Can someone point in the right direction? 有人可以指出正确的方向吗?

This is probably due to compatibility problems of Spring with Hibernate 4.3.0.Beta1 and newer reported here . 这可能是由于春季与Hibernate 4.3.0.Beta1并报告兼容性问题新在这里
If this is the problem a downgrade to Hibernate 4.1.7.Final should solve the problem. 如果这是问题所在,则降级到Hibernate 4.1.7.Final应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM