我已经实现了一个控制器@BasePathAwareController,它还利用了 Spring Data REST(用于查找以公开排序/大小等)以及一些自定义端点(用于更新等)。应用程序按预期工作,Spring Data REST 生成的端点按预期工作,我可以看到响应中出现自链接,但是,我在 Swagger UI 中看不到这些端点。我可以看到我的控制器中定义的自定义端点。
根据这篇文章,我需要使用3.0.0-SNAPSHOTSwagger@EnableSwagger2WebMvc
这是我的配置:
我的app.yml:
spring:
data:
rest:
basePath: /api/v1
我的POM文件:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
<properties>
<springfox.swagger.version>3.0.0-SNAPSHOT</springfox.swagger.version>
</properties>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>${springfox.swagger.version}</version>
</dependency>
招摇配置文件:
@Configuration
@Import(SpringDataRestConfiguration.class)
@EnableSwagger2WebMvc
public class SwaggerConfig {
@Bean
public Docket api(ServletContext servletContext) {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("my.package.name"))
.paths(PathSelectors.any())
.build().apiInfo(apiEndPointsInfo());
}
private ApiInfo apiEndPointsInfo() {
return new ApiInfoBuilder().title("My App REST API's")
.description("My App REST API's")
.version("1.0").build();
}
}
我的回购:
@RepositoryRestResource(exported=true, collectionResourceRel="group", path="group")
public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecificationExecutor<Group> {
}
为什么我看不到 Spring Data REST 生成的默认端点?