Himanshu Yadav
Himanshu Yadav

Reputation: 13587

Advantages/Disadvantages of configuring datasources at the application server level vs Spring's applicationContext

What is the best way to configure Datasources if application server may change client to client?

I have originally specified it in the application server itself. But now application servers are changing client to client. Clients are using many different application servers as JBOSS,Tomcat or Websphere etc.

Now it is becoming tedious for me as now it has to be configured as per the client specific server and I have to understand their application server configuartion.

That is why now I am moving datasource configuration to Spring's application context.

Upvotes: 3

Views: 1619

Answers (2)

Stefan Dorner
Stefan Dorner

Reputation: 171

I prefer configuring the database connection on the application level.

A good way to achieve this would be to define the relevant connection settings in a properties file located outside you web application, eg "/home/myuser/mywebapp/database.properties". You can then configure your spring application to read the properties from this file and create your datasource accordingly.

This way you can

  • avoid (re)configuring a client's application server
  • avoid holding your client's database settings on your build system, because you'll only need the location of their database properties file

Upvotes: 1

Suraj Chandran
Suraj Chandran

Reputation: 24791

There's a good alternative of keeping the datasource configuration within a database itself.

The web application is given the details for the master-config db, from where it reads the configuration for other databases.

Advantages:

  1. Changing db configs doesent require re-deployment. Just change in the master-config db.
  2. The context for all your web-apps will be similar and simple, since they wil only contain configuration for you master-config db.

Disadvantage:

  1. Won't be able to use the connection pooling and resource mgmt of container

Upvotes: 1

Related Questions