I don't think this is your problem, but look at section 8.3.7.5.4 of the pdf of the spring reference guide.
I had a problem where I wasn't extending AbstractTransactionalTestNGSpringContextTests but was (wrongly) extending AbstractTestNGSpringContextTests. But I think I was getting an error about the session being closed.
My class is
Code:
@Test(groups = { "db", "dao" })
@ContextConfiguration(locations = { "classpath:test-context.xml",
"FacilsDowaitlistDaoTest-context.xml" })
public final class FacilsDowaitlistDaoTest extends
AbstractTransactionalTestNGSpringContextTests {
private final transient Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private FacilsDowaitlistDao facilsDowaitlistDao;
/**
*/
@Test(groups = { "facilsDowaitlist" })
public void testGetFacilsDowaitlists() {
final List<Facility> facilsDowaitlist = facilsDowaitlistDao
.getFacilsDowaitlist();
for (final Facility eachFacilsDowaitlist : facilsDowaitlist) {
log.debug("fullName: {}", eachFacilsDowaitlist.getFullname());
}
}
}
FacilsDowaitlistDaoTest-context.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<beans:bean
id="facilsDowaitlistDao"
class="edu.berkeley.ist.waitlist.db.hbm.dao.FacilsDowaitlistDao">
</beans:bean>
</beans:beans>
test-context.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!--
wait list
-->
<!-- Activates annotation-based bean configuration -->
<context:annotation-config />
<!-- Scans for application @Components to deploy -->
<context:component-scan
base-package="edu.berkeley.ist.waitlist"
/>
<tx:annotation-driven
transaction-manager="transactionManager"
/>
<beans:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<beans:property
name="sessionFactory"
ref="sessionFactoryBean"
/>
</beans:bean>
<beans:bean
id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate"
p:sessionFactory-ref="sessionFactoryBean"
/>
<beans:bean id="sessionFactoryBean"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<beans:property
name="dataSource"
ref="dataSource"
/>
<beans:property
name="packagesToScan"
value="edu.berkeley.ist.waitlist.db.hbm.dto"
/>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">${hibernate.dialect}</beans:prop>
<beans:prop key="hibernate.default_schema">${hibernate.default_schema}</beans:prop>
<!-- <beans:prop key="hibernate.show_sql">${hibernate.show_sql}</beans:prop>-->
<!-- <beans:prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</beans:prop>-->
<beans:prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
<!-- c3p0 pooling data source -->
<beans:bean
id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="${jdbc-db2.driverClass}"
p:jdbcUrl="${db2.url}"
p:user="${db2.user}"
p:password="${db2.password}"
p:maxStatements="180"
p:idleConnectionTestPeriod="60"
p:testConnectionOnCheckin="true"
/>
</beans:beans>