Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
data-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
data-server
Commits
57104d9e
Commit
57104d9e
authored
Mar 09, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
3d115e18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
16 deletions
+9
-16
pom.xml
wisenergy-common/pom.xml
+1
-8
Swagger2.java
...c/main/java/cn/wisenergy/web/config/swagger/Swagger2.java
+8
-8
No files found.
wisenergy-common/pom.xml
View file @
57104d9e
...
...
@@ -89,9 +89,8 @@
<artifactId>
bcprov-jdk15on
</artifactId>
<version>
1.54
</version>
</dependency>
<!-- Swagger配置 -->
<
!--<
dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.9.2
</version>
...
...
@@ -120,13 +119,7 @@
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-models
</artifactId>
<version>
1.6.2
</version>
</dependency>-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-boot-starter
</artifactId>
<version>
3.0.0
</version>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/config/swagger/Swagger2.java
View file @
57104d9e
package
cn
.
wisenergy
.
web
.
config
.
swagger
;
import
io.swagger.v3.oas.models.security.SecurityScheme
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -12,14 +11,15 @@ import springfox.documentation.service.*;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.contexts.SecurityContext
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.time.LocalDate
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
//注解开启 swagger2 功能
@EnableSwagger2
//注解标示,这是一个配置类,@Configuation注解包含了@Component注解
//可以不用在使用@Component注解标记这是个bean了,
@Configuration
...
...
@@ -31,8 +31,7 @@ public class Swagger2 {
*/
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
OAS_30
)
.
apiInfo
(
apiInfo
())
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
select
()
//控制暴露出去的路径下的实例
//如果某个接口不想暴露,可以使用以下注解
...
...
@@ -40,7 +39,7 @@ public class Swagger2 {
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"cn.wisenergy.web.admin.controller"
))
.
paths
(
PathSelectors
.
any
())
.
build
()
.
protocols
(
new
LinkedHashSet
<>(
Arrays
.
asList
(
"HTTPS"
,
"HTTP"
)
))
.
apiInfo
(
apiInfo
(
))
.
pathMapping
(
"/"
)
.
directModelSubstitute
(
LocalDate
.
class
,
String
.
class
)
.
genericModelSubstitutes
(
ResponseEntity
.
class
)
...
...
@@ -63,17 +62,18 @@ public class Swagger2 {
}
private
ApiKey
apiKey
()
{
return
new
ApiKey
(
"BearerToken"
,
"Authorization"
,
SecurityScheme
.
In
.
HEADER
.
name
()
);
return
new
ApiKey
(
"BearerToken"
,
"Authorization"
,
"header"
);
}
private
SecurityContext
securityContext
()
{
return
SecurityContext
.
builder
()
.
securityReferences
(
defaultAuth
())
.
forPaths
(
PathSelectors
.
regex
(
"/.*"
))
.
build
();
}
List
<
SecurityReference
>
defaultAuth
()
{
AuthorizationScope
authorizationScope
=
new
AuthorizationScope
(
"global"
,
""
);
AuthorizationScope
authorizationScope
=
new
AuthorizationScope
(
"global"
,
"
accessEverything
"
);
AuthorizationScope
[]
authorizationScopes
=
new
AuthorizationScope
[
1
];
authorizationScopes
[
0
]
=
authorizationScope
;
return
newArrayList
(
new
SecurityReference
(
"BearerToken"
,
authorizationScopes
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment