【问题标题】:Loading String from file into Spring bean property将字符串从文件加载到 Spring bean 属性中
【发布时间】:2016-12-17 11:27:02
【问题描述】:

在我的 spring xml 文件中,我有一个 bean:

<bean id="config" class="com.example.BeanConfig">
        <property name="description" value="Long Description Here" />
</bean>

我想从 description.txt 中读取字符串,而不是定义长字符串内联。有没有办法在 xml 中执行此操作而无需编写 Java 类来处理它?

我已经遇到过How do I load a resource and use its contents as a string in Spring,但我不清楚如何将 bean 内容转换为属性值。

【问题讨论】:

    标签: java xml spring spring-mvc file-io


    【解决方案1】:

    您可以使用 Spring 的属性占位符和 ${property_name} 参见https://dzone.com/articles/properties-spring

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多