Announcement Announcement Module
No announcement yet.
Difference between JNDI datasource & DriverManagerDataSo Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between JNDI datasource & DriverManagerDataSo

    Does anyone know what is the recommended way to configure a datasource? Should you configure it in your app server (Tomcat, WebLogic) and access though JNDI or just use Spring's DriverManagerDataSource and configure the data source in your Spring config file?

    What are the differences between the two? I was wondering if only the app server method would utilize connection pooling.


  • #2
    If you're using distributed transactions you need to use a container JTA datasource. This means a full-blown J2EE server like WebLogic, rather than a web container like Tomcat, unless you combine the web container with a transaction coordinator like JOTM.

    However, most applications don't need distributed transactions. In that case there's no great advantage in using a container data source besides having a server-wide configuration.

    Spring is designed to make the choice transparent, so it's equally at home in either scenario.

    However, DriverManagerDataSource is not a solution for production apps--just a convenience for testing. Sure, app servers have connection pools, but there are also plenty of standalone connection pools such as Apache Commons DBCP. You should always use a connection pool in your application.