Java 如何使用Spring配置将文本文件内容设置为bean属性
我有一个包含数据的文本文件。我想将此数据设置为字符串实例变量 我知道我可以使用JavaI/O,读取文件并将其内容设置为字符串变量Java 如何使用Spring配置将文本文件内容设置为bean属性,java,spring,Java,Spring,我有一个包含数据的文本文件。我想将此数据设置为字符串实例变量 我知道我可以使用JavaI/O,读取文件并将其内容设置为字符串变量 但是有没有一种简单的方法可以使用Spring配置文件初始化字符串?尝试使用带有此xml标记的属性文件: <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <proper
但是有没有一种简单的方法可以使用Spring配置文件初始化字符串?尝试使用带有此xml标记的属性文件:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:YourFile.properties" />
</bean>
并将值用作${your_key}是的,您可以使用
Resource
执行此操作,然后对资源使用getFile()。检查spring文档。
还有更好的例子