1.引入依赖,创建配置类
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<scope>provided </scope>
</dependency>
创建SwaggerConfig配置类
@Configuration
@EnableSwagger2 //swagger注解
public class SwaggerConfig {
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("webApi")
.apiInfo(webApiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("API文档")
.description("本文档描述了微服务接口定义")
.version("1.0")
.contact(new Contact("zhang", "http://atkundi.com", "12345678@qq.com"))
.build();
}
}
启动类配置(如果不在一个模块内要进行引入)
@SpringBootApplication
@ComponentScan(basePackages = {"com.kundi"}) //为了扫描到SwaggerConfig
public class CrudApplication {
public static void main(String[] args) {
SpringApplication.run(CrudApplication.class,args);
}
}
启动启动类
访问