我只是想将 Swagger 集成到我使用 Gradle 构建的 Spring Boot (JAX-RS) 项目中。我能够生成docker (Swagger UI) 与以下内容相同:
我已经使用默认设置配置了我的 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/