spring-boot集成Springfox-Swagger2

spring-boot-springfox

  • spring-boot
  • Springfox
  • Swagger

效果图:
spring-boot集成Springfox-Swagger2_第1张图片


		io.springfox
		springfox-swagger2
		2.6.0


		io.springfox
		springfox-swagger-ui
		2.6.0

 


 

@Configuration  
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket adminApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Admin API")
                .forCodeGeneration(true)
                .pathMapping("/")
                .select()
                .paths(paths())
                .build()
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false);
    }

    private Predicate paths(){
        return Predicates.and(PathSelectors.regex("/.*"), Predicates.not(PathSelectors.regex("/error")));
    }


    private ApiInfo apiInfo(){
        Contact contact = new Contact("lance", "https://github.com/leelance", "[email protected]");
        return new ApiInfoBuilder()
                .title("Document Api")
                .description("Spring-boot-Springfox Example")
                .license("Apache License Version 2.0")
                .contact(contact)
                .version("2.0")
                .build();
    }
}

 

 项目完整路径:

 https://github.com/leelance/spring-boot-all/tree/master/spring-boot-springfox

 

 

你可能感兴趣的:(java)