Spring 3 JNDI在glassfish3中查找 [英] Spring 3 JNDI look up in glassfish3

查看:121
本文介绍了Spring 3 JNDI在glassfish3中查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从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查找。
! - >
< jee:jndi-lookup id =properties
jndi-name =java:comp / env / jndi / ws_properties
expected-type =java.util.Properties />

< / beans>

我在sun中映射了 jndi / ws_properties -web.xml和web.xml文件。问题是这个查找总是给我null属性。但是,如果我在java代码中执行它:

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

没关系。



有人可以告诉我问题在哪里吗?

方案

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


$ b 您不必将java:comp / env / 在名称中。



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


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?

解决方案

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.

这篇关于Spring 3 JNDI在glassfish3中查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆