依赖jar中的spring appContext.xml无法加载属性文件。

时间:2012-07-25 20:33:21

标签: java spring properties dependencies classpath

我有2个基于弹簧的jar文件 - parent.jar和child.jar。

parent.jar有一个parent_applicationContext.xml和一个它加载的属性文件,如下所示

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>classpath:app.properties</value>
    </list>
  </property>
  <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

<bean id="appBean" class="com.foo.App" >
    <property name="appName" value="${app.name}" />
</bean>

child.jar包含parent.jar作为依赖项,并具有自己的applicationContext.xml。 但是,当我执行child.jar时,我看不到parent_applicationContext.xml能够加载app.properties。

我看到了错误消息

Invalid bean definition with name 'appBean' defined in class path resource [parent_applicationContext.xml]: Could not resolve placeholder 'app.name'

任何线索。?

1 个答案:

答案 0 :(得分:0)

我设法通过在child.jar!applicationContext.xml中再次加载属性来解决它,就像这样,

<context:property-placeholder location="monitordb.properties" />