Springboot整合swagger2,包括修改swagger可视化界面和界面汉化处理
swagger配置类编写
package com.ruiec.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
/**
- swagger配置类
- @author luo_wei<br>
- @date 2019年5月8日 下午2:13:17
*/
@Configuration
//@EnableSwagger2 //启用Swagger2
public class SwaggerApi {
/**
- 创建Docket的Bean之后
- @author luo_wei<br>
- @date 2019年5月8日 下午2:10:26
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().
apis(RequestHandlerSelectors.basePackage("com.ruiec.controller")).paths(PathSelectors.any()).build();
}
/**
- 创建该Api的基本信息(这些基本信息会展现在文档页面中)
- @ApiIgnore无视
- @author luo_wei<br>
- @date 2019年5月8日 下午2:10:32
*/
@SuppressWarnings("deprecation")
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("大数据BI-JAVA部门对接项目").description("BI-前端api接口界面")
.termsOfServiceUrl("http://192.168.20.215:8081/swagger-ui.html").contact("罗巍").version("1.0.0").build();
}
}
jar包引入
<!-- 默认swagger-ui展示界面 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
src\main\r