?
Solved

Tomcat Datasource

Posted on 2014-03-04
12
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

800 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