Java spring jndi NamingException:名称 [spring.liveBeansView.mbeanDomain] 未在此上下文中绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23750619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:00:21  来源:igfitidea点击:

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

javaspringjndi

提问by lbear

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

我的带有 spring 3.2.4 的 webapp 运行良好。但是当我启动它时,我会得到调试信息:

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 c3p0as my dataSource, and the configuration is:

我不知道这些信息是什么意思。我用c3p0as my dataSource,配置是:

<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 JNDIis used in. I have search some questions about this exception. But they are always associated with @Profileor @Configuration. There is no @Profileor @Configurationin my code.

我找不到在何处JNDI使用。我搜索了有关此异常的一些问题。但它们总是与@Profileor相关联@Configuration。我的代码中没有@Profileor @Configuration

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

在我的 bean 类中,没有@Bean注释。信息是否与此有关?但是我不需要 spring 注入我的 bean 类。

采纳答案by rekinyz

if you don't use any profilesor mbeans, just add following context-paramsto the web.xmlas workaround (trick), hopefully there is someone can provide better solution than this ugly one.

如果您不使用任何配置文件mbeans,只需将以下上下文参数添加到web.xml作为解决方法(技巧),希望有人可以提供比这个丑陋的解决方案更好的解决方案。

<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>  

回答by Andrei Stefan

This is the JIRA issueand 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 commitfor this feature.

这是JIRA 问题,并简要解释了为什么在 Spring 3.2 中首次引入它。此外,您可以在此功能的初始提交中找到更多详细信息。

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.

基本上,这个特性是一种通过 JMX 公开存在于某个应用程序的应用程序上下文中的实时 bean 列表的方法。例如,您在 Tomcat 中部署了一个 web 应用程序,并在启动它时将它作为一个名为spring.liveBeansView.mbeanDomain. 假设您没有给它任何值,或者只是一个空字符串。Spring 会为此类属性搜索一长串可能的位置,并在系统环境中找到它。如果找到,它将知道通过 JMX 公开该活动 bean 列表(以 JSON 格式)。

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

如果您使用 JConsole 连接到您的 Tomcat 实例,您将看到一个名为的条目DefaultDomain,在它下面是您的应用程序的名称。如果你展开它,应该有一个属性被调用SnapshotAsJson,这是来自你的 webapp 应用程序上下文的实时 bean 列表。

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_domainand not DefaultDomain.

如果您想为系统环境变量赋值,比如说“test_domain”,那么在 JMX 中该条目将被调用test_domain而不是DefaultDomain.

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

所以,基本上你会看到那些 DEBUG 消息,因为 Springspring.liveBeansView.mbeanDomain在很长的位置列表中搜索属性,JNDI(在 JEE 服务器的情况下)就是其中之一。

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.

在 SpringSource Tool Suite 的最新版本(也许在一些更早的版本中)中,有一个特性可以利用这个名为“Live Beans Graph”的实时 bean JMX 公开,它采用该 JSON 表示并创建这些表示的基本图形表示豆子。