簡介
配置
Maven 配置
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<springfox.version>2.2.2</springfox.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--Swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
</dependencies>
Application配置
@MapperScan("com.anotherme17.anothernote.mapper")
@SpringBootApplication
@EnableSwagger2
public class AnothernoteApplication {
/*Swagger*/
@Bean
public Docket swaggerSpringMvcPlugin() {
ApiInfo apiInfo = new ApiInfo("A...", "= =", "1.0.0",
"", "...", null, null);
Docket docket = new Docket(DocumentationType.SWAGGER_2).select().paths(regex("/v1/*/.*")).build()
.apiInfo(apiInfo).useDefaultResponseMessages(false);
return docket;
}
public static void main(String[] args) {
SpringApplication.run(AnothernoteApplication.class, args);
}
}
配置完成
訪問接口 http://[服務(wù)器IP]:[端口號(hào)]/[項(xiàng)目名]/swagger-ui.html