Solved

Tomcat Datasource

Posted on 2014-03-04
12
299 Views
Last Modified: 2014-06-11
Hi  - I need to refer properties file in context.xml. For each environment I have different database names and need to tell to java app to use environment specific properties.

I configured  context.xml for each environment and every thing is working great.
ex: dev.xygpool
qat.xygpool
prd.xyzpool

The problem I am having is I have datasource name lmn and I need to configure the same name for prod and qat in context.xml. This is where I am having issues.

Can any one suggest best approach to configure datasource for each environment(dev,int,qat,prd)

All other property files I have are in environment specific folder and I am able to read all of the properties.

ex:
dev/xyz.properties
qat/xyg.properties
prd/xyz.properties

Any suggestions are welcome

Can we change userid and password and url dynamically in context.xml?
0
Comment
Question by:nzdjava
  • 4
  • 3
  • 2
12 Comments
 
LVL 61

Expert Comment

by:gheist
Comment Utility
easier will be to make two datasources and configure datasource name per-deployment/context and not use it directly by jsp-s
0
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
Comment Utility
You have to have different server.xml's for each environment, in this way your context.xml should not be changed.

try this suggested by Maurice:
I put all my datasource definitions in the conf/server.xml file of tomcat, so the war is completely independent of the datasource.

in server.xml
-------------------------------------
<GlobalNamingResources>
    <Resource name="mail/Mail" auth="Container" type="javax.mail.Session"
              mail.smtp.host="localhost"/>
    <Resource auth="Container" type="javax.sql.DataSource" name="jdbc/lagalerie"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost/lagalerie?charSet=LATIN1"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="casashop" password="casashop"/>
</GlobalNamingResources>
-------------------------------------

in context.xml
-------------------------------------
<ResourceLink global="jdbc/lagalerie" name="jdbc/lagalerie" type="javax.sql.DataSource"/>
  <ResourceLink global="mail/Mail" name="mail/Mail" type="javax.mail.Session"/>
-------------------------------------

in web.xml
-------------------------------------
<resource-ref>
    <description>The datasource</description>
    <res-ref-name>jdbc/DataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <description>The mail session</description>
    <res-ref-name>mail/Mail</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
-------------------------------------
0
 

Author Comment

by:nzdjava
Comment Utility
I've requested that this question be deleted for the following reason:

Didnt get correct way of approaching this
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
Comment Utility
Did you try my solution?
You have to change properly only the server.xml's on each one of the environments. Nothing more is needed.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 61

Expert Comment

by:gheist
Comment Utility
My first answer outlines similar idea too ;)
0
 

Author Comment

by:nzdjava
Comment Utility
Valleri - I cant modify server.xml in each environment. All we can do is package and deploy it in tomcat. It should be in our package. Let me know if I can do that.

Thanks for your help.

Thanks
0
 

Author Comment

by:nzdjava
Comment Utility
I've requested that this question be deleted for the following reason:

No t able to get the correct answers for this question
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
Sorry but months after it is completely wrong to pull out of the question mentioning some nonsense.
Tomcat provides JDBC connection pools, so the best place to define datasources is server.xml
That becomes especially critical when DBA wants to change database driver before or after DB upgrade and some even older drivers are planted in each web application.

Here you have http:#a39941623 correct answer to your question.
Ok it does not say it is bad to encapsulate driver in your webapp etc, but if you asked on how to plant it in webapp you would get exactly pointed to use app servers facilities...
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
Well yes, and it even includes cut from file to be changed.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now