Solved

Tomcat Datasource

Posted on 2014-03-04
12
311 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 62

Expert Comment

by:gheist
ID: 39905932
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
ID: 39908583
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
ID: 39941622
I've requested that this question be deleted for the following reason:

Didnt get correct way of approaching this
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 500 total points
ID: 39941623
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
 
LVL 62

Expert Comment

by:gheist
ID: 39941636
My first answer outlines similar idea too ;)
0
 

Author Comment

by:nzdjava
ID: 39962844
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
ID: 40128318
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 62

Expert Comment

by:gheist
ID: 40128314
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 62

Expert Comment

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

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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