@Data
    @ConfigurationProperties(prefix = “swagger2”)
    public class SwaggerProperties {
    /*
    包扫描的路径
    */
    _private String basePackage ;
    /
    联系人的名称
    /
    private String name ;
    /

    联系人的主页
    /
    private String url ;
    /
    联系人的邮箱
    /
    private String email ;
    /

    API的标题
    /
    private String title ;
    /
    API的描述
    /
    private String description ;
    /

    API的版本号
    /
    private String version ;
    /
    API的服务团队
    /
    _private String termsOfServiceUrl ;
    }
    SwaggerAutoConfiguration**

    1. @Configuration
    2. @EnableSwagger2
    3. @EnableConfigurationProperties(SwaggerProperties.class)
    4. public class SwaggerAutoConfiguration {
    5. private SwaggerProperties swaggerProperties;
    6. public SwaggerAutoConfiguration(SwaggerProperties swaggerProperties) {
    7. this.swaggerProperties = swaggerProperties;
    8. }
    9. @Bean
    10. public Docket docket() {
    11. Docket docket = new Docket(DocumentationType.SWAGGER_2)
    12. .apiInfo(apiInfo())
    13. .select()
    14. .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
    15. .paths(PathSelectors.any())
    16. .build();
    17. // 安全的配置
    18. docket.securitySchemes(securitySchemes()) // 安全规则
    19. .securityContexts(securityContexts()); // 安全配置的上下问
    20. return docket;
    21. }
    22. /**
    23. * api 信息的简介
    24. *
    25. * @return
    26. */
    27. private ApiInfo apiInfo() {
    28. return new ApiInfoBuilder().contact(
    29. new Contact(swaggerProperties.getName(), swaggerProperties.getUrl(), swaggerProperties.getEmail())
    30. )
    31. .title(swaggerProperties.getTitle())
    32. .description(swaggerProperties.getDescription())
    33. .version(swaggerProperties.getVersion())
    34. .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl())
    35. .build();
    36. }
    37. /**
    38. * 安全的规则配置
    39. *
    40. * @return
    41. */
    42. private List<SecurityScheme> securitySchemes() {
    43. return Arrays.asList(new ApiKey("Authorization", "Authorization", "Authorization"));
    44. }
    45. /**
    46. * 安全的上下问
    47. *
    48. * @return
    49. */
    50. private List<SecurityContext> securityContexts() {
    51. return Arrays.asList(new SecurityContext(
    52. Arrays.asList(new SecurityReference("Authorization", new AuthorizationScope[]{new AuthorizationScope("global", "accessResource")})),
    53. PathSelectors.any()
    54. ));
    55. }
    56. }