您好!
我有一个 spring 应用程序,它依赖于作为 jar 提供的遗留 spring 应用程序。请注意,遗留 jar 本身在 jar 中有其 spring 配置文件。那么有两个属性文件:app.properties 和 override.properties。
现在,我可以从外部项目读取一个配置属性,方法如下:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" ref="propertyResource"></property>
</bean>
<bean name="propertyResource" class="org.springframework.core.io.ClassPathResource">
<constructor-arg><value>spring-config.properties</value></constructor-arg>
</bean>
但我无法让它适用于 2 个属性文件。有人遇到过类似的问题并找到了出路吗?请建议。我尝试将列表用于 propertyResource
bean,有两个 PropertyPlaceholderConfigurer
bean,但没有用。
顺便说一句,为了记录,我搜索了(但不彻底)spring 文档,所以这将是我接下来要做的事情,但如果有人已经知道解决方案,为什么要重新发明轮子。
最佳答案
如果我没理解错的话,您正试图将多个属性文件加载到您的 PropertyPlaceholderConfigurer 中。您可以通过设置“位置”属性而不是“位置”属性来实现。
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:app.properties</value>
<value>classpath:override.properties</value>
</list>
</property>
</bean>
关于java - 在 Spring 中读取 jar 中存在的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4853056/