2012-03-28 58 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