-1

I am just configuring tomcat for JNDI using the externalized. I have done some thing wrong, but no clue.

In Context.xml

<Resource name="jdbc/AppDB" auth="Container" type="javax.sql.DataSource"
                            driverClassName="org.postgresql.Driver"
                            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                            url="${app.env.database.url}"
                            username="${app.env.database.user}"
                            password="${app.env.database.password}"
                            maxActive="100"
                            maxIdle="50"
                            minIdle="10"
                            suspectTimeout="60"
                            timeBetweenEvictionRunsMillis="30000"
                            minEvictableIdleTimeMillis="60000"
                            validationQuery="select 1"
                            validationInterval="30000"
                            testOnBorrow="true"
                            removeAbandoned="true"
                            removeAbandonedTimeout="60"
                            abandonWhenPercentageFull="10"
                            maxWait="10000"
                            jdbcInterceptors="ResetAbandonedTimer;StatementFinalizer"
            />

While running the Tomcat , I am setting this

-DappProperties=c:/user/abc/app.properties

On Starting the server, I am getting below error.

Caused by: javax.naming.NamingException: Driver:org.postgresql.Driver@d8cf794 returned null for URL:${app.env.database.url}
    at org.apache.naming.NamingContext.lookup(NamingContext.java:858)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 31 more

Can any one please help. Please note : application is working good if I change ${app.env.} with actual values.

Thank you for your help

user207421
  • 305,947
  • 44
  • 307
  • 483
Kumar
  • 1,106
  • 4
  • 15
  • 33
  • Refer this http://stackoverflow.com/questions/15064260/tomcat-jndi-configuration-best-practice – Sasikumar Murugesan May 18 '15 at 16:16
  • @Sasikumar Murugesan - That wont solve my problem. If you look into my question, conext.xml has ${app.env.url} etc which are supposed to inject through properties file on startup – Kumar May 18 '15 at 16:24
  • I don't know of any such functionality in Tomcat, nor can I find it in the documentation. Do you have a source where you read that this should be possible? – Gimby May 18 '15 at 20:18

1 Answers1

0

Are you using Maven? You need to use resource filtering plugin so maven will transform your property file values into actual values. Something like:

<build>
...
<resources>
  <resource>
    <directory>src/main/resources</directory>
  </resource>
  ...
</resources>
...

Where the directory contains your xml file should work

breakline
  • 5,776
  • 8
  • 45
  • 84
  • I think Maven is build tool and what I am looking is runtime assignment of the values. And How can I set tomcat/conf/server.xml property file through maven – Kumar May 18 '15 at 17:42
  • Here is a similar question which might help you: http://stackoverflow.com/questions/22118698/maven-tomcat7run-configure-datasource – breakline May 18 '15 at 17:58
  • Also my point was that you need to use some kind of build tool to transform the template variables into real ones. Maven can do that for you. – breakline May 18 '15 at 17:58
  • You are right, we can do that, but I need this for production use. I can not use Maven tomcat plugin for the production. – Kumar May 18 '15 at 18:00
  • Well I dont think you can do that without some tool. – breakline May 18 '15 at 18:05
  • I am sure, we can some how do with web.xml – Kumar May 18 '15 at 18:10