创建swagger2

依赖

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>

这里的version可根据项目进行调整,如果报缺失一些类,可根据类名到maven仓库中进行加包

配置swagger

@Configuration
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(ApiInfo.DEFAULT)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}

我这里是ssm项目,所以有@EnableWebMvc
要将SwaggerConfig放到spring中进行管理

posted @ 2020-08-23 22:32  自然的风和雨  阅读(135)  评论(0编辑  收藏  举报