簡體   English   中英

spring jndi NamingException:名稱[spring.liveBeansView.mbeanDomain]未綁定在此Context中

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

我的春季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]

我不知道這些信息是什么意思。 我使用c3p0作為我的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>

我找不到JNDI的用途。我已經搜索了一些關於這個例外的問題。 但它們始終與@Profile@Configuration相關聯。 我的代碼中沒有@Profile@Configuration

在我的bean類中,沒有@Bean注釋。 這些信息與此相關嗎? 但是我不需要spring注入我的bean類。

如果您不使用任何配置文件mbeans ,只需將以下context-params添加到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>  

這是JIRA問題,並簡要解釋了為什么它在第3季度第一次被引入。 此外,您可以在此功能的初始提交中找到更多詳細信息。

基本上,這個功能是一種通過JMX公開存在於某個應用程序的應用程序上下文中的bean的實時列表的方法。 例如,您在Tomcat中部署了一個Web應用程序,在啟動它時,您將其作為一個名為spring.liveBeansView.mbeanDomain的環境變量傳遞給它。 讓我們說你不給它任何值,或只是一個空字符串。 Spring會搜索這類屬性的一長串可能位置,並在系統環境中找到它。 如果發現它將知道通過JMX公開活動bean列表(采用JSON格式)。

如果您將JConsole連接到Tomcat實例,您將看到一個名為DefaultDomain的條目,並在其下面顯示您的應用程序名稱。 如果你擴展它應該有一個名為SnapshotAsJson的屬性,這是來自webapp的應用程序上下文的bean的實時列表。

如果你給你的系統環境變量一個值,讓我們說“test_domain”,在JMX中,這個條目叫做test_domain而不是DefaultDomain

所以,基本上你看到了那些DEBUG消息,因為Spring在一長串位置中搜索spring.liveBeansView.mbeanDomain屬性,JNDI(在JEE服務器的情況下)是其中之一。

在SpringSource Tool Suite的最新版本中(可能在某些早期版本中),有一個功能可以利用這個名為“Live Beans Graph”的活動JMX曝光,它采用JSON表示並創建一些基本的圖形表示。豆子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM