Spring 3 JNDI look up in glassfish3

守給你的承諾、 提交于 2019-12-23 03:47:06

问题


I want to look up some properties from JNDI configured in glassfish v3 server. I want to do it using spring. Here is my spring configuration:

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

I have mapped jndi/ws_properties in sun-web.xml and web.xml files. Problem is that this lookup always gives me null properties. But if I do it in java code:

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

It is ok. I see my properties keys and values.

Could somebody tell me where is the problem here?


回答1:


This is probably because of your "jndi-name" property.

You don't have to put "java:comp/env/" in the name.

The "resource-ref" property defaults to true and unless you set it to false, it will automatically add the java:comp/env to the name.



来源:https://stackoverflow.com/questions/9911624/spring-3-jndi-look-up-in-glassfish3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!