无法使用 JAX-RS 设置 Swagger



我不明白,为什么 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

获取 ->白标错误页面。

也许有人可以帮助我?

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

#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=/

你能分享完整的项目吗?

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

最新更新