Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring jndi NamingException: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context

Tags:

java

spring

jndi

My webapp with spring 3.2.4 is running fine. But when I start up it, I will get debug infos:

2014-05-20 11:11:47 DEBUG JndiTemplate:150 - Looking up JNDI object with name [java:comp/env/spring.liveBeansView.mbeanDomain]
2014-05-20 11:11:47 DEBUG JndiLocatorDelegate:101 - Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.NameNotFoundException: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find [spring.liveBeansView.mbeanDomain].
2014-05-20 11:11:47 DEBUG JndiTemplate:150 - Looking up JNDI object with name [spring.liveBeansView.mbeanDomain]
2014-05-20 11:11:47 DEBUG JndiPropertySource:87 - JNDI lookup for name [spring.liveBeansView.mbeanDomain] threw NamingException with message: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context. Unable to find [spring.liveBeansView.mbeanDomain].. Returning null.
2014-05-20 11:11:47 DEBUG PropertySourcesPropertyResolver:81 - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
2014-05-20 11:11:47 DEBUG PropertySourcesPropertyResolver:81 - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
2014-05-20 11:11:47 DEBUG PropertySourcesPropertyResolver:103 - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
2014-05-20 11:11:47 DEBUG DispatcherServlet:533 - Published WebApplicationContext of servlet 'spring' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring]

I don't know what the infos mean. I use c3p0 as my dataSource, and the configuration is:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>/WEB-INF/config/jdbc.properties</value>
            </list>
        </property>
    </bean>

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="autoCommitOnClose" value="true"/>
        <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
        <property name="initialPoolSize" value="${cpool.minPoolSize}"/>
        <property name="minPoolSize" value="${cpool.minPoolSize}"/>
        <property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
        <property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
        <property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
        <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="simpleJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="jdbcTemplate" />
    </bean>

I cant't find where JNDI is used in. I have search some questions about this exception. But they are always associated with @Profile or @Configuration. There is no @Profile or @Configuration in my code.

In my bean class, there is no @Bean annotation. Are the infos related to this? But I don't need spring inject my bean class.

like image 738
lbear Avatar asked May 20 '14 03:05

lbear


2 Answers

if you don't use any profiles or mbeans, just add following context-params to the web.xml as workaround (trick), hopefully there is someone can provide better solution than this ugly one.

<context-param>  
    <param-name>spring.profiles.active</param-name>  
    <param-value>dev</param-value>  
</context-param>  
<context-param>  
    <param-name>spring.profiles.default</param-name>  
    <param-value>dev</param-value>  
</context-param>
<context-param>  
    <param-name>spring.liveBeansView.mbeanDomain</param-name>  
    <param-value>dev</param-value>  
</context-param>  
like image 186
rekinyz Avatar answered Oct 13 '22 06:10

rekinyz


This is the JIRA issue and a short explanation about why it's been introduced first time in Spring 3.2. Also, a bit more details you can find in the initial commit for this feature.

Basically, this feature it's a way to expose through JMX a live list of beans that exist in an application context from a certain application. For example, you have a webapp deployed in Tomcat and upon starting it you pass to it as an environment variable one called spring.liveBeansView.mbeanDomain. And let's say you don't give it any value, or just an empty String. Spring searches a long list of possible locations for this kind of property and it's finding it in the system environment. If it's found it will know to expose that list of live beans (in JSON format) through JMX.

If you connect with JConsole to your Tomcat instance you will see an entry called DefaultDomain and under it your application's name. If you expand that there should be an attribute called SnapshotAsJson and this is the live list of beans from your webapp's application context.

If you would have given a value to your system environment variable, let's say "test_domain", in JMX the entry would have been called test_domain and not DefaultDomain.

So, basically you are seeing those DEBUG messages because Spring searches for spring.liveBeansView.mbeanDomain property in a long list of locations, JNDI (in case of JEE servers) being one of them.

In the latest version of SpringSource Tool Suite (and maybe in some earlier ones), there is a feature that makes use of this live beans JMX exposure called "Live Beans Graph" that takes that JSON representation and creates a somewhat basic graphic representation of those beans.

like image 31
Andrei Stefan Avatar answered Oct 13 '22 04:10

Andrei Stefan