2012-03-28 53 views
1

我想從glassfish v3服務器中配置的JNDI中查找一些屬性。我想用春天來做。這裏是我的Spring配置:Spring 3 JNDI在glassfish3中查找

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd 
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
          http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
          http://www.springframework.org/schema/jee 
          http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> 

    <import resource="classpath:META-INF/cxf/cxf.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> 

    <!-- 
     JNDI look ups. 
    !--> 
    <jee:jndi-lookup id="properties" 
        jndi-name="java:comp/env/jndi/ws_properties" 
        expected-type="java.util.Properties"/> 

</beans> 

我在sun-web.xml中和web.xml文件映射jndi/ws_properties。問題是這個查找總是給我null屬性。但如果我在java代碼中執行它:

try { 
     InitialContext context = new InitialContext(); 
     properties = (Properties) context.lookup("jndi/ws_properties"); 
    } catch (NamingException e) { 
     LOGGER.error("", e); 
    } 

沒關係。我看到我的屬性鍵和值。

有人能告訴我這裏的問題在哪裏嗎?

回答

2

這可能是因爲你的「jndi-name」屬性。

您不必在名稱中加入「java:comp/env /」。

「resource-ref」屬性默認爲true,除非將其設置爲false,否則它會自動將java:comp/env添加到名稱中。

+0

是的,謝謝你,我按照你說的那樣做了,它工作。 – 2012-05-05 18:36:23