我有一个 .properties 文件。我可以根据需要将属性注入 bean。现在,我希望能够按名称搜索属性。
例子:
conf.properties:
a.persons=person1,person2,person3
a.gender=male
我可以通过使用注释来注入这些属性。例如,
private @Value("${a.persons}") String[] persons
除此之外,我想搜索给定名称的属性的值,但我不知道如何去做。一个例子是这样的:
properties.get("a.gender")
这应该返回字符串“男性”。
这真的可能吗?
更新:我使用PropertyPlaceholderConfigurer
如下所示:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:META-INF/config/server.properties</value>
<value>classpath:META-INF/config/ke/dev.properties</value>
</list>
</property>
</bean>
我应该如何更改它以便可以将其注入到我的 bean 中?我将如何访问这些属性?提前致谢。