[英]How to set text file content to bean property using Spring configuration
I have a text file which contains data. 我有一个包含数据的文本文件。 I want to set this data to a String instance variable. 我想将此数据设置为String实例变量。
I know I can do it using Java I/O, read the file and set it's content to String variable. 我知道我可以使用Java I / O进行操作,读取文件并将其内容设置为String变量。
But is there a simplistic way to initialize the String using Spring configuration file? 但是,使用Spring配置文件初始化String的方法是否简单?
Try using properties file with this xml tags: 尝试使用带有以下xml标签的属性文件:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:YourFile.properties" />
</bean>
And use the values as ${your_key} 并将这些值用作$ {your_key}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.