|
@@ -0,0 +1,62 @@
|
|
|
|
+package com.gihon.common.swagger;
|
|
|
|
+
|
|
|
|
+import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.boot.web.context.WebServerInitializedEvent;
|
|
|
|
+import org.springframework.context.ApplicationListener;
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.context.annotation.Import;
|
|
|
|
+import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
|
|
|
+import springfox.documentation.builders.ApiInfoBuilder;
|
|
|
|
+import springfox.documentation.builders.PathSelectors;
|
|
|
|
+import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
|
+import springfox.documentation.service.ApiInfo;
|
|
|
|
+import springfox.documentation.spi.DocumentationType;
|
|
|
|
+import springfox.documentation.spring.web.plugins.Docket;
|
|
|
|
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
|
+
|
|
|
|
+import java.net.Inet4Address;
|
|
|
|
+import java.net.InetAddress;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Knife4j配置
|
|
|
|
+ */
|
|
|
|
+@Configuration
|
|
|
|
+@EnableSwagger2
|
|
|
|
+@EnableKnife4j
|
|
|
|
+@Import(BeanValidatorPluginsConfiguration.class)
|
|
|
|
+public class Knife4jConfig implements ApplicationListener<WebServerInitializedEvent> {
|
|
|
|
+
|
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(Knife4jConfig.class);
|
|
|
|
+
|
|
|
|
+ @Bean(value = "web")
|
|
|
|
+ public Docket createRestAdmin() {
|
|
|
|
+ return new Docket(DocumentationType.SWAGGER_2)
|
|
|
|
+ .useDefaultResponseMessages(false)
|
|
|
|
+ .groupName("web")
|
|
|
|
+ .apiInfo(apiInfo())
|
|
|
|
+ .select()
|
|
|
|
+ .apis(RequestHandlerSelectors.basePackage("com.gihon.controller"))
|
|
|
|
+ .paths(PathSelectors.any())
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ApiInfo apiInfo() {
|
|
|
|
+ return new ApiInfoBuilder()
|
|
|
|
+ .title("权限验证")
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onApplicationEvent(WebServerInitializedEvent event) {
|
|
|
|
+ try {
|
|
|
|
+ InetAddress inetAddress = Inet4Address.getLocalHost();
|
|
|
|
+ logger.info("\033[1;33m项目启动成功!接口文档地址: http://" + inetAddress.getHostAddress() + ":" + event.getWebServer().getPort() + event.getApplicationContext().getEnvironment().getProperty("server.servlet.context-path") + "/doc.html\033[0m");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|