Using DataSource without app-server
My data access objects takes a DataSource as a parameter which works perfectly if they are deployed within an app server.
I'm wondering how I can assemble a data source f开发者_开发技巧rom within a simple Java class. This might also be useful for unit testing?!
There's nothing magic about a DataSource. It's just an interface. Spring has a basic one for testing purposes if you're already using Spring. Apache DBCP is all about providing a pooling DataSource. Pretty much any other JDBC connection pooling library out there will also provide a DataSource implementation. Just instantiate it, set the properties, and run with it.
精彩评论