Spring jndi NamingException: Name [spring.liveBeansView.mbeanDomain] is not related in this context

My webapp with spring 3.2.4 is working fine. But when I run it, I will get debugging information:

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 do not know what information means. 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 can not find where JNDI used. I have a search for some questions about this exception. But they are always associated with @Profile or @Configuration . There is no @Profile or @Configuration in my code.

There is no @Bean annotation in my bean class. Is this information related? But I don't need spring to introduce a bean class.

+8
java spring jndi
source share
2 answers

if you do not use profiles or mbeans , just add the following contextual parameters to web.xml as a workaround (trick), hope someone can provide a 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> 
+11
source share

This is a JIRA issue and a brief explanation of why it was first introduced in Spring 3.2. In addition, you can find more detailed information in the initial commit for this function.

In principle, this function allows you to open through JMX a live list of beans that exists in the application context from a specific application. For example, you have a webapp deployed to Tomcat, and after you launch it, you go to it as an environment variable called spring.liveBeansView.mbeanDomain . And let them say that you don’t give it any value or just an empty String. Spring searches for a long list of possible locations for these kinds of properties and finds it in the system environment. If he discovers that he will know that this list of live beans (in JSON format) through JMX will be shown.

If you are connecting from JConsole to an instance of Tomcat, you will see an entry called DefaultDomain and below it is your application name. If you expand it, there must be a SnapshotAsJson attribute, and this is a live list of beans from your webapp application context.

If you set the value of your system environment variable, say, "test_domain", the JMX entry would be called test_domain , not DefaultDomain .

So basically you see these DEBUG messages because Spring is looking for the spring.liveBeansView.mbeanDomain property in a long list of locations, one of which is JNDI (in the case of JEE servers).

The latest version of the SpringSource Tool Suite (and possibly some earlier versions) has a feature that uses this JMX beans environment called "Live beans Graph", which takes this JSON representation and creates a somewhat basic graphical representation of these beans.

+7
source share

All Articles