【问题标题】:can't set up swagger with jax-rs无法使用 jax-rs 设置招摇
【发布时间】:2019-12-19 17:34:46
【问题描述】:

我不明白,为什么 swagger 不适用于我的 spring boot jax-rs 应用程序。

我将此依赖项添加到 pom.xml:

                <!-- Swagger -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
        <version>3.3.4</version>
    </dependency>
     <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>swagger-ui</artifactId>
        <version>3.1.5</version>
    </dependency> 

我还在应用程序属性中设置了 -> cxf.jaxrs.component-scan=true,我的休息请求:

@Path("/")
@Api("/")
@Service
public interface IService {

  @GET
  @Path("/health")
  @ApiOperation("/health")
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Status getStatus();

  @GET
  @Path("/info")
  @ApiOperation("/info")
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Info getInfo();

}

按我的预期工作,但是当我打电话时无法获得文档:

http://localhost:8000/swagger-ui.html

get -> Whitelabel 错误页面。

也许有人可以帮助我?

以防万一这是我的属性文件:

#cxf url mapping
cxf.path=/api
cxf.jaxrs.component-scan=true
cxf.jaxrs.classes-scan-packages=com,org.apache.cxf.jaxrs.swagger.Swagger2Feature,org.codehaus.jackson.jaxrs,org.apache.cxf.jaxrs.swagger.ui.SwaggerUiResourceLocator

#port
server.port=8000
server.servlet.context-path=/

【问题讨论】:

    标签: swagger jax-rs cxf


    【解决方案1】:

    你能分享一下完整的项目吗?

    您可以在 https://github.com/apache/cxf/tree/cxf-3.3.4/distribution/src/main/release/samples/jax_rs 中找到工作示例,如果您开始一个新项目,我建议您使用 OpenAPI v3 而不是 Swagger。

    【讨论】:

    • 谢谢,我会尝试使用这个示例来完成我的任务。
    猜你喜欢
    • 2019-01-10
    • 2013-08-27
    • 1970-01-01
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2017-10-06
    相关资源
    最近更新 更多