首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Springfox不显示文档

Springfox不显示文档
EN

Stack Overflow用户
提问于 2016-01-31 23:08:44
回答 1查看 625关注 0票数 0

我正在尝试将Swagger添加到我的Spring MVC项目中。我正在使用这个依赖项

代码语言:javascript
复制
    <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

代码语言:javascript
复制
@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();
    }
}

我还添加了要注册的资源处理程序

代码语言:javascript
复制
   registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

   registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

我已经将@ApiModel(...)@ApiModelProperty(...)添加到我的模型类中,我的api类也被注释如下。

代码语言:javascript
复制
@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

EN

回答 1

Stack Overflow用户

发布于 2016-02-19 22:09:52

我知道为时已晚。但我猜这会对别人有帮助。

以及你上面所有的改变。尝试将以下更改添加到spring-servlet.xml配置文件中。

代码语言:javascript
复制
<mvc:annotation-driven />

<!-- Swagger config bean -->
<bean class="<---package--->.SwaggerConfig"/>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35115341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档