开发者

How to get a DBUnit DatabaseConnection instance from Spring JdbcTemplate instance

I'm trying to use a Spring JdbcTemplate instance to generate a DataSet useable for subsequent 开发者_如何转开发DBUnit tests.

any ideas how to do that?

all the documentation I found where going from a JDBC Connection instance to a IDatabaseConnection instance.

But the code I have abstract all this away using Spring, and what I have is a JdbcTemplate instance.

Any ideas?


Your jdbcTemplate bean has a dataSource property, so you can either get it from the jdbcTemplate with its getter or inject the dataSource (which you already have defined somewhere in your applicationContext) in your class where you build the IDatabaseConnection and use it as a constructor-arg for that. (you should do the latter)

See the following blog for a detailed explanation and full example (written by a springsource trainer)

  • http://blog.zenika.com/index.php?post/2010/02/04/Testing-SQL-queries-with-Spring-and-DbUnit%2C-part-1
  • http://blog.zenika.com/index.php?post/2010/02/05/Testing-SQL-queries-with-Spring-and-DbUnit%2C-part-2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜