访问spring引导应用程序中spring-restdocs生成的内容



我在Spring Boot (v1.4.1)应用程序中使用Spring Restdocs (v1.1.2)。

在Gradle构建文件的jar任务中,我将生成的输出复制到public/docs中:
jar {
  dependsOn asciidoctor
  from ("${asciidoctor.outputDir}/html5") {
    into 'public/docs'
  }
}
我在生成的JAR中看到 中的文档
BOOT-INF/classes/public/docs/api-guide.html

但是,当我运行JAR时,我似乎无法在/docs,/public/docs等处处理api-guide.html。

有人能解释一下我做错了什么吗?

谢谢!

——约翰。

buildscript {
    ext {
        springBootVersion = '1.4.1.RELEASE'
    }
}
plugins {
    id "org.asciidoctor.convert" version "1.5.3"
}
apply plugin: 'groovy'
apply plugin: 'spring-boot'
ext {
    snippetsDir = file('build/generated-snippets')
    springRestdocsVersion = '1.1.2.RELEASE'
}

test {
    outputs.dir snippetsDir
}
asciidoctor {
    attributes 'snippets': snippetsDir
    inputs.dir snippetsDir
    dependsOn test
}
jar {
    dependsOn asciidoctor
    from ("${asciidoctor.outputDir}/html5") {
        into 'public/docs'
    }
}
dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    testCompile("org.springframework.restdocs:spring-restdocs-mockmvc:${springRestdocsVersion}")
}

=============================================================

下面是应用程序配置:

@SpringBootApplication
@EnableJpaRepositories
@EnableScheduling
class Application {
    static void main(String[] args) {
        SpringApplication.run Application, args
    }
}

和测试配置:

@RunWith(SpringJUnit4ClassRunner)
@SpringApplicationConfiguration(classes = Application)
class ApplicationTests {
    ...
}

好了,我终于知道我哪里做错了。我启用了spring-boot-actuator-docs:

compile('org.springframework.boot:spring-boot-actuator-docs')

并且它正在"接管"/docs路径。只要我将生成的restdocs重新定位到不同的路径,例如

jar {
    dependsOn asciidoctor
    from ("${asciidoctor.outputDir}/html5") {
        into 'static/api'
    }
}

一切都好。

感谢Andy对我的问题和非常酷的Spring REST文档项目感兴趣!

最新更新