我有一个下面的项目结构

项目产品和API网关共享公共项目作为公共项目。由于在父项目settings.Gradle中,我将该项目包含在下面
rootProject.name = 'src'
include 'common', 'fetebird-apigateway', 'fete-bird-product'在API网关build.gradle中,我包含了以下依赖项
dependencies {
annotationProcessor("io.micronaut.openapi:micronaut-openapi:2.1.1")
implementation("io.swagger.core.v3:swagger-annotations")
implementation project(':common')
}在产品build.gradle中,我包含了以下依赖项
dependencies {
annotationProcessor("io.micronaut.openapi:micronaut-openapi:2.1.1")
implementation("io.swagger.core.v3:swagger-annotations")
implementation project(':common')
}当我运行命令$ gradle build时,我可以看到视图已经生成

Swagger暴露端点
micronaut:
application:
name: feteBirdProduct
server:
port: 8083
router:
versioning:
enabled: true
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**但当我访问URL时
http://localhost:8084/swagger-ui/index.html
我可以看到下面的消息,但我没有启用任何安全保护
{"message":"Page Not Found","_links":{"self":{"href":"/swagger-ui/index.html","templated":false}}}调试io.micronaut.web.router.resource.StaticResourceResolver时。BuiltinClassLoader.java中的public URL findResource(String name)返回null

发布于 2020-10-19 18:25:13
不确定您是否这样做了,但您可能需要将生成的API文档公开为带有YML配置的静态资源,例如在Micronaut OpenAPI docs中声明的如下内容:
micronaut:
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**然后,您应该能够使用诸如:http://localhost:8080/swagger/views/swagger-ui/index.html之类的路由访问它们。
如果您启用了安全模块,则可能需要使用"intercept URL map“为该URL指定安全规则,否则可能无法访问:
micronaut:
security:
intercept-url-map:
- pattern: /swagger/**
http-method: GET
access:
- isAnonymous()发布于 2020-11-03 17:04:04
解决方案是包含每个项目的setting.gradle文件,但是在Intellj上,如果你导航到Gradle任务并运行构建,它会给你一个错误,或者如果你运行gradle run it,它会给你一个错误
发布于 2021-03-09 15:44:43
文档显示enabled标志的默认值是true,但由于某种原因,我必须显式设置this value才能显示swagger ui。
micronaut:
router:
static-resources:
swagger:
enabled: true # docs says this is already the default value
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
enabled: true # but this only works if it is explicitly set
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**https://stackoverflow.com/questions/64412985
复制相似问题