如何从多个文件中收集spring属性以在单个bean上使用 [英] How to collect spring properties from multiple files for use on a single bean
问题描述
我还没有把头包裹在Spring周围,所以如果这个问题没有意义,请纠正我...
I haven't gotten my head wrapped around Spring yet, so correct me if this question doesn't make sense...
我有一个PropertyPlaceholderConfigurer
I have a PropertyPlaceholderConfigurer
<bean id="rdbmPropertiesPlacholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="false">
<property name="location" value="classpath:/properties/rdbm.properties" />
</bean>
我猜有豆子注入?
<bean id="PortalDb" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${hibernate.connection.driver_class}" />
<property name="url" value="${hibernate.connection.url}" />
<property name="username" value="${hibernate.connection.username}" />
<property name="password" value="${hibernate.connection.password}" />
...
我想要的是第二个占位符指向不同的属性文件用户名/密码,以便我可以将属性拆分为两个不同的文件。然后数据库连接信息可以与db用户名/密码分开,我可以控制一个而不是另一个。
What I want is a second placeholder pointing to a different properties file with the username/password so that I can split up the properties into two different files. Then the database connection information can be separate from the db username/password, and I can source control one and not the other.
我已经尝试过基本上复制rdbmPropertiesPlaceholder了一个不同的id和文件,并尝试访问属性,但它不起作用。
I've tried basically copying the rdbmPropertiesPlaceholder with a different id and file and trying to access the properties, but it doesn't work.
此代码来自uPortal开源Web门户项目。
This code is from the uPortal open source web portal project.
推荐答案
使用此表示法可以指定多个文件:
Using this notation lets you specify multiple files:
<bean id="rdbmPropertiesPlacholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="false">
<property name="locations">
<list>
<value>classpath:/properties/rdbm.properties</value>
<value>classpath:/properties/passwords.properties</value>
</list>
</property>
</bean>
propertyplaceholderconfigurerer只是合并所有这些看起来只有一个,所以你的bean定义不知道属性来自哪里。
The propertyplaceholderconfigurerer just merges all of these to look like there's only one, so your bean definitions do not know where the properties come from.
这篇关于如何从多个文件中收集spring属性以在单个bean上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!