【问题标题】:Spring 3 JNDI look up in glassfish3Spring 3 JNDI 在 glassfish3 中查找
【发布时间】:2012-03-28 16:13:53
【问题描述】:

我想从 glassfish v3 服务器中配置的 JNDI 中查找一些属性。我想用弹簧来做。这是我的弹簧配置:

<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。问题是这个查找总是给我空属性。但是如果我用java代码来做:

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

没关系。我看到了我的属性键和值。

谁能告诉我问题出在哪里?

【问题讨论】:

    标签: spring glassfish jndi


    【解决方案1】:

    这可能是因为您的“jndi-name”属性。

    您不必在名称中加上“java:comp/env/”。

    “resource-ref”属性默认为 true,除非您将其设置为 false,否则它会自动将 java:comp/env 添加到名称中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      相关资源
      最近更新 更多