Spring Can';I don’我不能让PropertyPlaceHolderConfigure按我想要的方式工作

Spring Can';I don’我不能让PropertyPlaceHolderConfigure按我想要的方式工作,spring,configuration,Spring,Configuration,我正在尝试使用PropertyPlaceHolderConfigure读取我的应用程序配置。基本上,WEB-INF/config/config.properties中有第一个配置文件,其中包含另一个属性文件的文件系统位置(以便在应用程序部署或更新期间不会销毁该文件)。我试图在servlet context.xml中设置它,但只有第一个有效: <bean id="propertyConfigurerInternal" class="org.springframework.beans.

我正在尝试使用PropertyPlaceHolderConfigure读取我的应用程序配置。基本上,
WEB-INF/config/config.properties
中有第一个配置文件,其中包含另一个属性文件的文件系统位置(以便在应用程序部署或更新期间不会销毁该文件)。我试图在
servlet context.xml
中设置它,但只有第一个有效:

<bean id="propertyConfigurerInternal"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>/WEB-INF/config/config.properties</value>
    </property>
</bean>


<bean id="propertyConfigurerExternal"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    depends-on="propertyConfigurerInternal">
    <property name="location">
        <value>file:${baseDataFolder}/jaccise.conf</value>
    </property>
</bean>

/WEB-INF/config/config.properties
文件:${baseDataFolder}/jaccise.conf
第一个(
PropertyConfigureInternal
)创建时没有问题,但第二个失败如下:

org.springframework.beans.factory.BeanInitializationException
:无法加载属性;嵌套异常是
java.io.FileNotFoundException
${baseDataFolder}\jaccise.conf
(不可能的trovare il percorso specificato)您可以这样做:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>/WEB-INF/config/config.properties</value>
            <value>file:${baseDataFolder}/jaccise.conf</value>
        </list>
    </property>
</bean>

/WEB-INF/config/config.properties
文件:${baseDataFolder}/jaccise.conf
只需使用一个占位符配置器,看看这是否是问题的原因。我从未见过两个实例被创建成您正在尝试的样子,我猜这可能会有问题

希望这有帮助。

依赖于=“PropertyConfigureInternal”
意味着
PropertyConfigureInternal
PropertyConfigureExternal
之前初始化

${baseDataFolder}
必须包含在
propertyconfigureInternal
的属性文件中(在您的示例中:
config.properties
),否则无法对其进行分析


因此,您应该查看您的
/WEB-INF/config/config.properties
,查看文件中是否设置了
${baseDataFolder}

我认为您不能这样做。所有
属性PlaceHolderConfigure
bean一起初始化,然后进行替换。所以他们不能互相引用。那你怎么解决这样的问题呢?