新建1个java类
ApiDocConfig.java @Configuration @EnableSwagger2 @EnableKnife4j @Import(BeanValidatorPluginsConfiguration.class) public class ApiDocConfig { private final ServerProperties serverProperties; private final SysInfoProperties sysInfoProperties; public Knife4jConfig(ServerProperties serverProperties, SysInfoProperties sysInfoProperties) { this.serverProperties = serverProperties; this.sysInfoProperties = sysInfoProperties; } private ApiInfo apiInfo() { String serviceUrl = "http://localhost:" + serverProperties.getPort() + serverProperties.getServlet().getContextPath(); return new ApiInfoBuilder() .title("xxxx服务后台接口文档") .description("xxxx服务") .termsOfServiceUrl(serviceUrl) .version(sysInfoProperties.getVersion()) .contact(new Contact(sysInfoProperties.getPic(), null, "wq6e54@123.com")) .build(); } @Bean(value = "defaultApi2") public Docket defaultApi2() { Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) //分组名称 .groupName("1.X版本接口") .select() //这里指定Controller扫描包路径 .apis(RequestHandlerSelectors.basePackage("com.xxxxx.contentstatistics.web")) .paths(PathSelectors.any()) .build(); return docket; } }