lundi 18 mai 2015

How to do JNDI in Tomcat by using externalized Property file

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

Aucun commentaire:

Enregistrer un commentaire