propsFileName is the name of the bean, which should be initialized with
the string value from the JNDI entry "propertiesFileName" defined in
$CATALINA_HOME/conf/context.xml

This was working, stopped working until a tomcat restart, and is working
again now. My concern is that this may be a bug in tomcat 

So what happens is that tomcat startup creates a JNDI environment entry
in the "cross-application" context called "propertiesFileName". 

<Environment name="/propertiesFileName"
value="classpath:test-application.properties" type="java.lang.String"
override="true"/>

When each spring app starts, the code <jee:jndi-lookup
id="propsFileName" jndi-name="propertiesFileName"/> in the application
context takes the JNDI environment entry and initializes a bean using
the id "propsFileName" with it.

Finally a spring PropertyPlaceholderConfigurer is created using the
propsFileName bean for the location of the properties file. We use this
to 

     <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfi
gurer">
        <property name="location" ref="propsFileName"/>
     </bean>

Looking more closely at the debug log, this line looks quite suspicious
"Name comp is not bound". comp is the root of the environment hierarchy,
why would that be missing?

2010-12-08 19:29:11,161 DEBUG ** Converted JNDI name
[java:comp/env/propertiesFileName] not found - trying original name
[propertiesFileName]. javax.naming.NameNotFoundException: Name comp is
not bound in this Context **
org.springframework.jndi.JndiObjectFactoryBean 

Log context follows:

2010-12-08 19:29:11,108 DEBUG ** Creating instance of bean
'propsFileName' **
org.springframework.beans.factory.support.DefaultListableBeanFactory
2010-12-08 19:29:11,116 DEBUG ** Eagerly caching bean 'propsFileName' to
allow for resolving potential circular references **
org.springframework.beans.factory.support.DefaultListableBeanFactory
2010-12-08 19:29:11,158 DEBUG ** Invoking afterPropertiesSet() on bean
with name 'propsFileName' **
org.springframework.beans.factory.support.DefaultListableBeanFactory
2010-12-08 19:29:11,158 DEBUG ** Looking up JNDI object with name
[java:comp/env/propertiesFileName] **
org.springframework.jndi.JndiTemplate
2010-12-08 19:29:11,161 DEBUG ** Converted JNDI name
[java:comp/env/propertiesFileName] not found - trying original name
[propertiesFileName]. javax.naming.NameNotFoundException: Name comp is
not bound in this Context **
org.springframework.jndi.JndiObjectFactoryBean
2010-12-08 19:29:11,161 DEBUG ** Looking up JNDI object with name
[propertiesFileName] ** org.springframework.jndi.JndiTemplate
2010-12-08 19:29:11,164 INFO  ** Destroying singletons in
org.springframework.beans.factory.support.defaultlistablebeanfact...@493
02473: defining beans
[propsFileName,org.springframework.beans.factory.config.PropertyPlacehol
derConfigure
2010-12-08 19:29:11,165 ERROR ** Context initialization failed **
org.springframework.web.context.ContextLoader

-----Original Message-----
From: Christopher Schultz [mailto:ch...@christopherschultz.net] 
Sent: Tuesday, 14 December 2010 9:46 a.m.
To: Tomcat Users List
Subject: Re: jndi-lookup fails, cured by tomcat restart

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dale,

On 12/13/2010 3:08 PM, Dale Ogilvie wrote:
> We are using a spring jndi-lookup to pull the name of a context file 
> from the global "environment" in our apps. We have set this up in 
> tomcat
> 6.0.29 like so:
> 
> $CATALINA_HOME/conf/context.xml

Technically speaking, I think that's the default local environment, not
the global environment. You can define <Environment> entries at the
<Server> level in server.xml which would be truly "global". It's all
semantics for this discussion and shouldn't impact this case.

> <Environment name="/propertiesFileName"
> value="classpath:test-application.properties" type="java.lang.String"
> override="true"/>
> 
> This has worked fine for lots of applications, but last week it 
> started failing for one application when it was redeployed. This 
> results in the application failing to start.
> 
> The error message below suggests that the environment value cannot be 
> found.
> 
> Tomcat 6.0.29 log output:
>  
> 2010-12-08 19:27:24,674 DEBUG ** Invoking afterPropertiesSet() on bean

> with name 'propsFileName' **

'propsFileName' != 'propertiesFileName'

Are you sure you're looking at the right configuration file?

> org.springframework.beans.factory.BeanCreationException: Error 
> creating bean with name 'propsFileName': Invocation of init method 
> failed; nested exception is javax.naming.NameNotFoundException: Name 
> propertiesFileName is not bound in this Context

Perhaps propsFileName is bound, but not propertiesFileName.

> Spring application web.xml
> 
>     <context-param>
>         <param-name>contextConfigLocation</param-name>
>         <param-value>
>             classpath:applicationContext-shared.xml
>         </param-value>
>     </context-param>
> 
>     <listener>
>  
> <listener-class>org.springframework.web.context.ContextLoaderListener<
> /l
> istener-class>
>     </listener>
> 
> applicationContext-Shared.xml
> 
>     <jee:jndi-lookup id="propsFileName" jndi-name="propertiesFileName"
> />
> 
>     <bean
> class="org.springframework.beans.factory.config.PropertyPlaceholderCon
> fi
> gurer">
>        <property name="location" ref="propsFileName"/>
>     </bean>

I don't see where the data is ultimately defined... I just see a bunch
of references that don't point to anything. propertiesFileName ->
propsFileName -> ???

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0GhfkACgkQ9CaO5/Lv0PB5OQCfa20jn6k8gt/jvp211sFgA+KZ
YRsAn3FFKu9rx2BidCKz64FKo+Vnb7LO
=HtIz
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to