Search code examples
javahibernatespringintegration-testingjndi

How do I swap a jndi datasource lookup to an in memory database for intergration testing?


I'm using Spring and Hibernate and want to do some intergration testing with DBUnit. In my application-context.xml I currently specify a datasource via jndi-lookup which reads the jndi-name from a properties file:

<jee:jndi-lookup id="dataSource" 
   jndi-name="${datasource.myapp.jndi}"
   cache="true"
   resource-ref="true"
   proxy-interface="javax.sql.DataSource" />

I'd like to swap this out to an in memory database (hsqldb, h2 etc) for integration testing by just supplying a new properties file, is this possible? Or should I just use a different application-context.xml for the integration testing?


Solution

  • This is why Spring 3.1 introduced profiles: http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/

    Upgrade application to 3.1 or use different configs for integrations tests.