【问题标题】:Setting values of attributes in asciidoctor during Spring's MockMvc building在 Spring 的 MockMvc 构建期间设置 asciidoctor 中的属性值
【发布时间】:2017-01-24 12:40:29
【问题描述】:

我正在使用 Spring MVC 和 Spring Test suite(Spring REST Docs),我想知道在使用 MockMvcBuilders 构建 MockMvc 期间是否可以在 asciidoctor adoc 文件中设置属性值?

例如我在 index.adoc 中

:我的属性:

并希望在 MockMvc 构建期间动态设置它?

:myAttribute: myValue

我在 asciidoctor 文档中看到:

默认情况下,属性分配优先级,从最高到 最低,如下:

Attribute passed to the API or CLI

Attribute defined in the document

Default value

我想知道如何将它传递给 API :-)

【问题讨论】:

    标签: java spring-mvc spring-test asciidoctor spring-restdocs


    【解决方案1】:

    我能想到的有两种方法可以做到这一点。在这两种情况下,您都会在运行测试时将属性键值对写入文件中。然后你需要让它们进入 Asciidoctor。

    让它们进入 Asciidoctor 的一种方法是更新构建配置以读取文件,然后设置属性。我怀疑这只有在您使用 Gradle 时才有可能。您可以编写一点 Groovy 来读取键值对并将它们添加到 asciidoctor 任务的 attributes 映射中。

    另一种方法是编写一个 AsciidoctorJ 扩展,读取包含键值对的文件并设置属性。这种方法适用于 Maven 或 Gradle。文档中有一个 example 说明如何使用 Preprocessor 设置属性。

    【讨论】:

    • 您好,安迪,感谢您的回答。尽管我放弃了使用这种方法,但我会接受它是正确的。事实证明,每次部署我都会有不同的 maven POM,我可以使用“Value of the attr'标签轻松地通过“asciidoctor-maven-plugin”设置属性,所以不会很麻烦。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多