4

我不知道该怎么做。要求是我想使用 JNDI 加载属性文件,然后使用自定义属性解析器和配置解析器来使用其数据。问题是我如何配置 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 及其宁静的网络服务 .. 如果这有任何关系

4

0 回答 0