• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Configur password dynamically to context.xml in tomcat

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am trying to connect my spring web app to DB2 by fetching the creds from an external system. On server startup the password is queried from an external storage successfully and is available in the class file. Now I need to pass the password to context.xml ${dbPwd}. Could you please suggest on how can i do so?

<Resource auth=" Container" factory="com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory" maxPoolSize="10" name="jdbc/xyz" type="com.atomikos.jdbc.AtomikosDataSourceBean" uniqueResourceName="MyDB" xaDataSourceClassName="com.ibm.db2.jcc.DB2XADataSource" xaProperties.databaseName="DB2T" xaProperties.driverType="4" xaProperties.password="${dbPwd}" xaProperties.portNumber="3000" xaProperties.serverName="xyx.abc.com" xaProperties.user="ABC"/>
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally you should not be passing database connection information into your web application, you should be using a database connection pool. That will not only keep sensitive information outside of the webapp entirely, it will also allow you to use database connections more efficiently.

There are exceptions to that rule. I have a database editor program where instead of a fixed connection pool I select the database that the web application user will be working with as part of the web application logic.

In the case of providing connection credentials to the Spring application context, you can use JNDI in association with the application resources definition in web.xml, which can be overridden by the webapp server-specific deployment descriptor (in Tomcat, that's the Context).

A Spring JNDI element would look like this:


That particular element then defines a spring bean that can be referenced by (injected into) other Spring objects.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic