1

I have looked at a couple of posts regarding JNDI and ways to manage datasource configuration. My question is: what are the pros and cons of:

  1. externalizing the configuration of datasources (by any means, context.xml, server.xml whatever) versus:
  2. keeping the configuration within the war's context.xml
Community
  • 1
  • 1
Bartosz Radaczyński
  • 18,396
  • 14
  • 54
  • 61

1 Answers1

6

The main reason that I have seen for using a web container's data source management mechanism, usually exposed through JNDI, is to keep the keys to the kingdom out of the developer's hands. I've worked mainly at financial institutions and have found that the passwords for the production databases are usually quite well-protected. If the application server admins are the only members of the application team that know how to connect to the production databases, there is less risk of someone else reading data that they are not supposed to.

Ryan Ransford
  • 3,224
  • 28
  • 35
  • +1. And to complement your answer - as long as you have an application being deployed to multiple environments its always a pro to externalize as much of the configuration as possible. – Perception Feb 28 '12 at 22:30
  • that is also one of the things I thought about (apart from the local/dev/qa/stage/prod environments) - are there any cons (e.g. I would think it would make it more difficult to share the same config across multiple people in a team)? – Bartosz Radaczyński Feb 28 '12 at 22:33
  • There is a setup process for getting the JNDI datasources set up on each developer's machine. For developer environments however, there is usually not a problem with creating team/developer credentials with appropriate access. – Ryan Ransford Feb 28 '12 at 22:36
  • How about deployment of mulitple instances of the same webapp on the same app server (each accessing a different datasource)? Is that doable? – Bartosz Radaczyński Feb 29 '12 at 10:27
  • Quick answer: It depends. Does your container support per-application JNDI resources? If not, you will have to also externalize your resource name (properties file) or custom-build your application for each instance. – Ryan Ransford Feb 29 '12 at 14:18