首页 > 解决方案 > 如何使用 Spring JndiObjectFactoryBean 为 tomcat7 设置 jndiname 属性值?我这里的属性值是一个文件

问题描述

我正在尝试将在 jboss5 中运行的 web 应用程序转换为 tomcat7。我需要更改元数据属性的 JNDI 配置才能在 tomcat 中工作。元数据属性在外部属性文件中配置,并且必须在应用程序启动期间加载属性文件。

<bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>                
            <bean class="org.springframework.core.io.FileSystemResource">
                <constructor-arg>
                    <bean class="org.springframework.jndi.JndiObjectFactoryBean">
                        <property name="jndiName" value="${CATALINA_HOME}/conf/metadata.properties" />                           
                    </bean>
                </constructor-arg>
            </bean>                
       </list>
    </property>
</bean>

应用程序应该加载 jndiName 属性值,但它不工作。它抛出以下错误,

Caused by: javax.naming.NameNotFoundException: Name [${CATALINA_HOME}/conf/metadata.properties] is not bound in this Context. Unable to find [${CATALINA_HOME}].

而为 jboss 提供了相同的配置。取而代之的${CATALINA_HOME}"external/config/"

你们能帮我看看我是否错过了tomcat的任何其他配置。

(我还在文件中定义${CATALINA_HOME}了环境变量,catalina.sh并且其他属性文件已正确加载。即使我给出绝对路径,它也会显示相同的错误。)

Caused by: javax.naming.NameNotFoundException: Name [root/user1/apache-tomcat-7.0.92/conf/metadata.properties] is not bound in this Context. Unable to find [root].

标签: javaspringtomcat

解决方案


推荐阅读