SpringMVC整合Swagger(非Spring Boot)
阿新 • • 發佈:2018-10-11
width acf audio cnblogs restfu sele type img sep
1.新建項目
1.1 maven項目
1.2 設置項目名
1.3 設置本地maven
1.4 finish
2.添加依賴
打開pom文件,添加下面的依賴
[sourcecode language=‘xml‘ padlinenumbers=‘true‘] <!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> [/sourcecode]
3.添加Swagger的配置類
[sourcecode language=‘java‘ ] @Configuration @EnableWebMvc @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.whu505.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Person RESTful API文檔") .description("Person Controller的文檔") .termsOfServiceUrl("") .version("1.0") .build(); } } [/sourcecode]
SpringMVC整合Swagger(非Spring Boot)