Difference between a Spring datasource and a Tomcat datasource?
What is the difference between a Spring datasource and开发者_开发百科 Tomcat datasource? Any pro's / con's? Is there a favored choice?
When using a Tomcat datasource you have to drop the JDBC driver JAR file(s) in Tomcat's classpath (the Tomcat/lib
). This is sometimes not affordable/possible, for example when it concerns 3rd party hosting with zero server admin rights. When using a Spring managed datasource, it's sufficient to just drop the JDBC driver JAR file(s) in webapp's classpath (the Webapp/WEB-INF/lib
). Plus, I'd imagine that you've in Spring the additional benefit that you don't need to grab the DataSource
manually. Also, you have the freedom of choosing a specific connection pool. Also, Tomcat ships with DBCP builtin as default connection pool which is not the best choice per se. With Spring, you could for example choose BoneCP above DBCP without the need to fiddle with Tomcat default configuration/classpath.
If you have a datasource in the Spring config, you associate it with a Tomcat datasource when you are in a web application. You can associate it with something else, for example Spring DriverManagerDataSource when you run unit tests.
精彩评论