我正在尝试将Swagger添加到我的Spring MVC项目中。我正在使用这个依赖项
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.5</version>
</dependency>这是我的SwaggerConfig
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(apiInfo());
}
@Bean
public UiConfiguration uiConfig() {
return UiConfiguration.DEFAULT;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("My awesome API")
.description("Some description")
.version("1.0")
.contact("my-email@domain.org")
.build();
}
}我还添加了要注册的资源处理程序
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");我已经将@ApiModel(...)和@ApiModelProperty(...)添加到我的模型类中,我的api类也被注释如下。
@RestController
@RequestMapping("/api")
@Api(description = "Test")
public class RestServer {
@ApiOperation(value = "Gets all tags")
@RequestMapping(value = "/alltags", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public List<Tag> getAllTags() {
return (List<Tag>) tagRepo.findAll();
}
}我只得到了http://localhost:5001/swagger-ui.html

发布于 2016-02-19 22:09:52
我知道为时已晚。但我猜这会对别人有帮助。
以及你上面所有的改变。尝试将以下更改添加到spring-servlet.xml配置文件中。
<mvc:annotation-driven />
<!-- Swagger config bean -->
<bean class="<---package--->.SwaggerConfig"/>https://stackoverflow.com/questions/35115341
复制相似问题