2

What is the difference between a Spring datasource and Tomcat datasource? Any pro's / con's? Is there a favored choice?

Marco
  • 15,101
  • 33
  • 107
  • 174
  • You mean http://stackoverflow.com/questions/5941523/if-i-create-a-spring-datasource-do-i-still-need-to-define-the-datasource-inside ? – Tomasz Nurkiewicz May 09 '11 at 20:02
  • I agree that the questions are somewhat related, the previous question is all about the implementation. This one however, is more about if there a differences between the two and why we should or should not make a choice for a specific implementation. – Marco May 09 '11 at 20:04

2 Answers2

5

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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.

Olaf
  • 6,249
  • 1
  • 19
  • 37