Commit 1448d669 by XiaHou

first提交

parent c12e167d
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<element id="library" level="project" name="Maven: io.springfox:springfox-swagger-ui:2.7.0" /> <element id="library" level="project" name="Maven: io.springfox:springfox-swagger-ui:2.7.0" />
<element id="library" level="project" name="Maven: io.springfox:springfox-spring-web:2.7.0" /> <element id="library" level="project" name="Maven: io.springfox:springfox-spring-web:2.7.0" />
<element id="library" level="project" name="Maven: org.reflections:reflections:0.9.11" /> <element id="library" level="project" name="Maven: org.reflections:reflections:0.9.11" />
<element id="library" level="project" name="Maven: org.javassist:javassist:3.21.0-GA" />
<element id="library" level="project" name="Maven: io.springfox:springfox-swagger2:2.7.0" /> <element id="library" level="project" name="Maven: io.springfox:springfox-swagger2:2.7.0" />
<element id="library" level="project" name="Maven: io.swagger:swagger-annotations:1.5.13" /> <element id="library" level="project" name="Maven: io.swagger:swagger-annotations:1.5.13" />
<element id="library" level="project" name="Maven: io.swagger:swagger-models:1.5.13" /> <element id="library" level="project" name="Maven: io.swagger:swagger-models:1.5.13" />
...@@ -115,6 +114,8 @@ ...@@ -115,6 +114,8 @@
<element id="library" level="project" name="Maven: com.gexin.platform:gexin-rp-sdk-base:4.0.0.30" /> <element id="library" level="project" name="Maven: com.gexin.platform:gexin-rp-sdk-base:4.0.0.30" />
<element id="library" level="project" name="Maven: com.google.protobuf:protobuf-java:2.5.0" /> <element id="library" level="project" name="Maven: com.google.protobuf:protobuf-java:2.5.0" />
<element id="library" level="project" name="Maven: com.gexin.platform:gexin-rp-fastjson:1.0.0.3" /> <element id="library" level="project" name="Maven: com.gexin.platform:gexin-rp-fastjson:1.0.0.3" />
<element id="library" level="project" name="Maven: com.github.xiaoymin:swagger-bootstrap-ui:1.9.6" />
<element id="library" level="project" name="Maven: org.javassist:javassist:3.25.0-GA" />
</element> </element>
</element> </element>
<element id="directory" name="META-INF"> <element id="directory" name="META-INF">
......
<component name="libraryTable"> <component name="libraryTable">
<library name="Maven: org.javassist:javassist:3.21.0-GA"> <library name="Maven: com.github.xiaoymin:swagger-bootstrap-ui:1.9.6">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/github/xiaoymin/swagger-bootstrap-ui/1.9.6/swagger-bootstrap-ui-1.9.6.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/github/xiaoymin/swagger-bootstrap-ui/1.9.6/swagger-bootstrap-ui-1.9.6-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.21.0-GA/javassist-3.21.0-GA-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/github/xiaoymin/swagger-bootstrap-ui/1.9.6/swagger-bootstrap-ui-1.9.6-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.javassist:javassist:3.25.0-GA">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.25.0-GA/javassist-3.25.0-GA.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.25.0-GA/javassist-3.25.0-GA-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.25.0-GA/javassist-3.25.0-GA-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.7.0" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.7.0" level="project" />
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.7.0" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.7.0" level="project" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.11" level="project" /> <orderEntry type="library" name="Maven: org.reflections:reflections:0.9.11" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.7.0" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.7.0" level="project" />
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.13" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.13" level="project" />
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.13" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.13" level="project" />
...@@ -180,5 +179,7 @@ ...@@ -180,5 +179,7 @@
<orderEntry type="library" name="Maven: com.gexin.platform:gexin-rp-sdk-base:4.0.0.30" level="project" /> <orderEntry type="library" name="Maven: com.gexin.platform:gexin-rp-sdk-base:4.0.0.30" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.5.0" level="project" /> <orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.5.0" level="project" />
<orderEntry type="library" name="Maven: com.gexin.platform:gexin-rp-fastjson:1.0.0.3" level="project" /> <orderEntry type="library" name="Maven: com.gexin.platform:gexin-rp-fastjson:1.0.0.3" level="project" />
<orderEntry type="library" name="Maven: com.github.xiaoymin:swagger-bootstrap-ui:1.9.6" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.25.0-GA" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
...@@ -264,7 +264,12 @@ ...@@ -264,7 +264,12 @@
<artifactId>gexin-rp-sdk-http</artifactId> <artifactId>gexin-rp-sdk-http</artifactId>
<version>4.1.0.5</version> <version>4.1.0.5</version>
</dependency> </dependency>
<!-- 重写Swagger-UI -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
......
package com.hwstudio.antaile.config; package com.hwstudio.antaile.config;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -7,28 +9,100 @@ import springfox.documentation.builders.ApiInfoBuilder; ...@@ -7,28 +9,100 @@ import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/** /**
* SwaggerConfig * SwaggerConfig
*/ */
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class SwaggerConfig { public class SwaggerConfig {
/**
* 是否开启swagger
*/
@Value("${swagger.enabled}")
private boolean enabled;
/**
* 设置请求的统一前缀
*/
@Value("${swagger.pathMapping}")
private String pathMapping;
/**
* 创建API
*/
@Bean @Bean
public Docket buildDocket() { public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(buildApiInf()).select() return new Docket(DocumentationType.SWAGGER_2)
.apis(RequestHandlerSelectors.basePackage("com.hwstudio.antaile.controller"))// controller路径 // 是否启用Swagger
.paths(PathSelectors.any()).build(); .enable(enabled)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.apiInfo(apiInfo())
// 设置哪些接口暴露给Swagger展示
.select()
// 扫描所有有注解的api,用这种方式更灵活
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
// 扫描指定包中的swagger注解
// .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
// 扫描所有 .apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
/* 设置安全模式,swagger可以设置访问token */
.securitySchemes(securitySchemes())
.securityContexts(securityContexts())
.pathMapping(pathMapping);
}
/**
* 安全模式,这里指定token通过Authorization头请求头传递
*/
private List<ApiKey> securitySchemes() {
List<ApiKey> apiKeyList = new ArrayList<ApiKey>();
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
return apiKeyList;
}
/**
* 安全上下文
*/
private List<SecurityContext> securityContexts() {
List<SecurityContext> securityContexts = new ArrayList<>();
securityContexts.add(
SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("^(?!auth).*$"))
.build());
return securityContexts;
}
/**
* 默认的安全上引用
*/
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
List<SecurityReference> securityReferences = new ArrayList<>();
securityReferences.add(new SecurityReference("Authorization", authorizationScopes));
return securityReferences;
} }
private ApiInfo buildApiInf() { private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("").termsOfServiceUrl("#").description("springmvc swagger2") return new ApiInfoBuilder().title("安泰乐app后台-接口文档")
.version("0.1").build(); .termsOfServiceUrl("#")
.description("描述:用于app后台-开发人员测试,以及调试请求接口")
.version("1.0")
.build();
} }
} }
...@@ -58,5 +58,10 @@ spring: ...@@ -58,5 +58,10 @@ spring:
poolPreparedStatements: true poolPreparedStatements: true
maxOpenPreparedStatements: 20 maxOpenPreparedStatements: 20
connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000 connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000
swagger:
# 是否开启swagger
enabled: true
# 请求前缀
pathMapping: / #dev-api
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment