对比新文件 |
| | |
| | | package com.se.simu.config; |
| | | |
| | | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
| | | import springfox.documentation.builders.ApiInfoBuilder; |
| | | import springfox.documentation.builders.PathSelectors; |
| | | import springfox.documentation.builders.RequestHandlerSelectors; |
| | | import springfox.documentation.service.ApiInfo; |
| | | import springfox.documentation.service.Contact; |
| | | import springfox.documentation.spi.DocumentationType; |
| | | import springfox.documentation.spring.web.plugins.Docket; |
| | | |
| | | @Configuration |
| | | @EnableKnife4j |
| | | @SuppressWarnings("ALL") |
| | | public class Knife4jConfig extends WebMvcConfigurationSupport { |
| | | @Value("${server.port}") |
| | | String serverPort; |
| | | |
| | | @Value("${knife4j.enabled}") |
| | | private boolean enabled; |
| | | |
| | | @Value("${knife4j.pathMapping}") |
| | | private String pathMapping; |
| | | |
| | | @Value("${server.servlet.context-path}") |
| | | String contextPath; |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | registry.addResourceHandler("doc.html") |
| | | .addResourceLocations("classpath:/META-INF/resources/"); |
| | | |
| | | registry.addResourceHandler("swagger-ui.html") |
| | | .addResourceLocations("classpath:/META-INF/resources/"); |
| | | registry.addResourceHandler("/webjars/**") |
| | | .addResourceLocations("classpath:/META-INF/resources/webjars/"); |
| | | } |
| | | |
| | | @Bean |
| | | public Docket createRestApi() { |
| | | return new Docket(new DocumentationType("openApi", "3.0")) |
| | | .enable(enabled) |
| | | .apiInfo(apiInfo()) |
| | | .groupName("鏈嶅姟") |
| | | .select() |
| | | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
| | | // .apis(RequestHandlerSelectors.basePackage("com.cn.project.tool.swagger")) |
| | | .paths(PathSelectors.any()) |
| | | .build() |
| | | // .securitySchemes(securitySchemes()) |
| | | .pathMapping(pathMapping); |
| | | } |
| | | |
| | | private ApiInfo apiInfo() { |
| | | return new ApiInfoBuilder() |
| | | .description("鎺ュ彛鏂囨。") |
| | | .contact(new Contact("WuWeiwei", "http://127.0.0.1:" + serverPort + contextPath + "/doc.html", "252740454@qq.com")) |
| | | .version("0.2") |
| | | .title("鍐呮稘浠跨湡鏈嶅姟鏈嶅姟鎺ュ彛鏂囨。") |
| | | .build(); |
| | | } |
| | | } |