【问题标题】:Spring REST Docs : Read Spring property from .adoc fileSpring REST Docs:从 .adoc 文件中读取 Spring 属性
【发布时间】:2016-12-01 15:02:39
【问题描述】:

我正在使用很棒的 Spring REST Docs 来生成我的 Spring Data Rest 应用程序的文档。 为此,我将生成的 sn-ps 包含在 .adoc 文件中,然后以 HTML 呈现(完全如 Spring REST Docs 文档中所述)。

我的问题:是否可以从 .adoc 文件中读取 Spring 属性(例如,在 application.properties 中定义)?

谢谢你:)

【问题讨论】:

  • 不可能开箱即用,但 Asciidoctor 的可扩展性非常好,所以我很确定您可以编写一些代码来做到这一点。你的用例是什么?
  • 另外,您使用的是什么构建系统?我认为使用 Gradle 可以很容易地做到这一点。

标签: spring-restdocs


【解决方案1】:

@Andy Wilkinson:非常感谢您的快速回答!

确实,使用 Gradle 可以做到这一点。我没有意识到,但我已经使用默认的 asciidoctor 任务将属性“注入”到 .adoc 文件中,如 Spring REST Docs 文档中所述。

添加自定义属性(build.gradle):

ext {
    myProperty='here my custom property'
}

asciidoctor {
    ...
    attributes 'my-property': myProperty
}

my-property 现在可以在 .adoc 文件中使用。

添加至此并为基本问题提供解决方案,以下是如何在 Spring 属性文件中使用 Gradle 属性。

build.gradle 中:

processResources {
    filesMatching('**/*.properties') { expand([
            myProperty: myProperty
    ])}
}

application.properties 中:

api.myProperty=${myProperty}

现在可以在 Gradle 构建文件中定义一次属性 myProperty,然后在 Spring 属性和 asciidoctor 文档中使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 2016-04-29
    • 1970-01-01
    • 2018-10-27
    相关资源
    最近更新 更多