java - Apache Spring - 具有多行属性值的 Bean

标签 java spring

有没有办法分解 Spring bean 的属性值,使其位于多行上?

<bean>
    <property name="something" value="Hello, this is a red fox jumping over a not very brown cow.">
</bean>

我知道在 Java 属性文件中,我可以在每行末尾放置一个“\”,但以下内容不适用于 Spring bean 的属性值:

<bean>
    <property name="something" value="Hello, this is a \
                                      red fox jumping over a \
                                      not very brown cow.">
</bean>

最佳答案

XML 属性允许跨行,并且解析器将非空格空白字符替换为空格。因此,对于您的示例,您可以使用:

<bean name="foo" class="Foo">
    <property name="bah" value=
"Hello, this is a
red fox jumping over a
not very brown cow." />
</bean>

那么“foo”中“bah”的值为

"Hello, this is a red fox jumping over a not very brown cow."

如果你尝试让它像这样整洁

<bean name="foo" class="Foo">
    <property name="bah" value=
        "Hello, this is a
        red fox jumping over a
        not very brown cow." />
</bean>

您将在解析结果中获得额外的空格字符。

Hello, this is a    red fox jumping over a    not very brown cow.

关于java - Apache Spring - 具有多行属性值的 Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47402705/

相关文章:

java - 如何使用数组对象?

java - Android OpenGLES 1.0 视口(viewport)以错误的分辨率呈现

ios - 在 URLSession.uploadTask :with :fromFile 上设置边界

java - 在 Spring Boot 中急切加载单例对象,无需注释

spring - 在 STS 3.1 的 Spring Data JpaRepository 接口(interface)中到处出现 "Invalid derived query"错误

eclipse - 使用 Spring 框架的 Eclipse 中的 Java Web App 无法识别对 Controller 的编辑

java - 使用Thread查找2个键的最小距离

java - 理解我的代码有什么问题的问题

java - 两个方法同时使用@Asynchronous注解

java - Spring框架-同一类型的多个ModelAttributes