使用JNDI加载.properties文件

时间:2012-07-25 09:56:07

标签: java jndi

我不知道怎么做。要求是我想使用JNDI加载属性文件,然后使用Custom propertiesresolver和配置解析器来使用其数据。问题是我如何配置JNDI来查找此属性文件。 我的配置是:

<bean id="MYUrlResource" class="org.springframework.core.io.UrlResource">
    <!-- <constructor-arg value="file:C:\Users\anand_rajneesh\Desktop\SVN Workspace\13MM - Dev\web-app\src\main\resources\application.properties"/> -->
    <constructor-arg>
        <bean class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:comp/env/url/application.properties" />
            <property name="resourceRef" value="false" />
            <property name="lookupOnStartup" value="true" />
        </bean>
    </constructor-arg>
</bean>

和我的web.xml:

<resource-ref>
        <description>Property File Url</description>
        <res-ref-name>url/application.properties</res-ref-name>
        <res-type>java.net.url</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

我不明白我该怎么办?使用此当前配置我得到以下异常,显然jndi名称错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jndi.JndiObjectFactoryBean#149a794' defined in ServletContext resource [/WEB-INF/classes/application-context.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name application.properties is not bound in this Context
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
    ... 48 more
Caused by: javax.naming.NameNotFoundException: Name application.properties is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:774)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:144)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:785)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:144)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:785)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:144)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:785)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:157)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    ... 51 more

我正在使用Tomcat 7.0 Eclipse Indigo及其一个宁静的网络服务..如果这与它有任何关系

0 个答案:

没有答案