spring - Swagger 2 (Spring Fox) 将 'es' 添加到我的 API 中

标签 spring spring-boot jax-rs swagger-ui swagger-2.0

我只是想将 Swagger 集成到我使用 Gradle 构建的 Spring Boot (JAX-RS) 项目中。我能够生成docker (Swagger UI) 与以下内容相同: Swagger UI Docker

我已经使用默认设置配置了我的 swagger,如下所示:

package com.abc;

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableAutoConfiguration
@SpringBootApplication
@EnableMongoRepositories
@Slf4j
@Import({springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class,springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration.class})
@EnableSwagger2
public class ServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
    }

    public static void run(String[] args) throws Exception{
        log.info("Started application on: 8080");
    }
}

正如我们在 GET Events API 的图像中看到的那样,docker 显示了/eventses .. 所以从它添加的位置 >es 到/events API,写为:

@GET
public HashMap<String, Object> getEventList(@DefaultValue("1") @QueryParam("page") int page,
        @DefaultValue("10") @QueryParam("rpp") int rpp, @QueryParam("events") String eventIds) {
    HashMap<String, Object> eventsResultMap= new HashMap<String, Object>();

    List<Events> events = null;

    if (eventIds != null && eventIds.length() > 0) {
        List<String> eventsIdList = Arrays.asList(eventIds.split(","));
        log.info("" + eventsIdList);
        events = eventService.getEvents(eventsIdList);
    } else {
        events = eventService.getEvents(page - 1, rpp);
    }
    eventsResultMap.put("EVENTS", events);

    HashMap<String, Object> recordsMetaMap = new HashMap<String, Object>();
    recordsMetaMap.put("total", eventService.totalCount());
    recordsMetaMap.put("page", page);
    recordsMetaMap.put("rpp", rpp);
    eventsResultMap.put("_metadata", recordsMetaMap);
    log.info("The events you have queried for are:" + eventsResultMap);
    return eventsResultMap;
}

请指导我哪里做错了。需要完成哪些自定义配置。

我已经拿了Reference来自spring官方文档。

最佳答案

/eventses 中的所有内容均来自 Springfox 对 Spring Data REST 的支持,与 Controller 中的 getEventList 方法无关。如果您不想像这样自动发现实体,则从 @Import 行中删除该类应该可以解决问题。

关于spring - Swagger 2 (Spring Fox) 将 'es' 添加到我的 API 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42591978/

相关文章:

java - org.springframework.mapping

java - 如何使用@Query在JPA中获取自动生成的 key ?

java - 读取Spring Boot嵌入式Tomcat中的context.xml

spring-boot - 具有 spring boot 2.0.0 的样板项目未公开自定义执行器端点

java - 使用 JAX-RS 时返回对象列表

tomcat - 如何使用 Apache cxf/jaxrs 拒绝非 https 请求

java - 在 spring 中只加载一次 xml 文件

java - 我可以直接从 SpEL 表达式创建 bean 吗?

java - 按日期排序 聚合 mongodb

java - Restful WebService 的问题