如何解决使用Micronaut多模块项目gradle构建无法访问swagger ui
我的项目结构如下
项目产品和API网关共享共同的共同项目。由于在上级项目设置中。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
时,我可以看到视图已生成
昂首阔步地暴露终点
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
时。 public URL findResource(String name)
在BuiltinClassLoader.java中返回null
解决方法
不确定是否这样做,但是您可能需要使用YML配置将生成的API文档公开为静态资源,例如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()
,
解决方案是包括每个项目的setting.gradle文件,但是在Intellj上,如果您导航到Gradle任务并运行构建,则会给您一个错误,或者如果您运行gradle run会给您一个错误
,文档说 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/**
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。