Solved

Tomcat Datasource

Posted on 2014-03-04
12
305 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
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
 
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 61

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 61

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 61

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

867 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

16 Experts available now in Live!

Get 1:1 Help Now