Gar*_*our 12 java spring configuration-files
我已经知道如何:
使用以下命令将属性文件加载到Spring配置中
<context:property-placeholder location="aaa/bbb/ccc/stuff.properties"/>
Run Code Online (Sandbox Code Playgroud)
使用以下方法动态构建属性对象:
<props><prop key="abc">some value</prop></props>
Run Code Online (Sandbox Code Playgroud)
但我无法做到并且真正有用的是让Spring加载一个属性文件,然后构建匹配的属性对象.然后我可以正常方式将它注入bean中.
我在其他地方搜索过这个但没有成功.有任何想法吗?
too*_*kit 17
正如@ MetroidFan2002所暗示的那样,看一下util:properties
<util:properties id="myProperties" location="classpath:com/foo/my.properties"/>
Run Code Online (Sandbox Code Playgroud)
然后,要将Properties注入Spring管理的Bean,它就像这样简单:
@Resource(name = "myProperties")
private Properties myProperties;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16825 次 |
| 最近记录: |