Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
discovery
Commits
086fe7ac
Commit
086fe7ac
authored
Jul 05, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加Swagger接口
parent
e8e0e306
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
discovery-plugin-router-center/src/main/java/com/nepxion/discovery/plugin/routercenter/configuration/SwaggerConfiguration.java
+87
-0
No files found.
discovery-plugin-router-center/src/main/java/com/nepxion/discovery/plugin/routercenter/configuration/SwaggerConfiguration.java
0 → 100644
View file @
086fe7ac
package
com
.
nepxion
.
discovery
.
plugin
.
routercenter
.
configuration
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
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.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
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
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
public
class
SwaggerConfiguration
extends
WebMvcConfigurerAdapter
{
@Value
(
"${spring.application.name}"
)
private
String
serviceName
;
@Value
(
"${swagger.service.base.package}"
)
private
String
basePackage
;
@Value
(
"${swagger.service.description}"
)
private
String
description
;
@Value
(
"${swagger.service.version}"
)
private
String
version
;
@Value
(
"${swagger.service.license}"
)
private
String
license
;
@Value
(
"${swagger.service.license.url}"
)
private
String
licenseUrl
;
@Value
(
"${swagger.service.contact.name}"
)
private
String
contactName
;
@Value
(
"${swagger.service.contact.url}"
)
private
String
contactUrl
;
@Value
(
"${swagger.service.contact.email}"
)
private
String
contactEmail
;
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
basePackage
))
// 扫描该包下的所有需要在Swagger中展示的API,@ApiIgnore注解标注的除外
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
serviceName
)
.
description
(
description
)
.
version
(
version
)
.
license
(
license
)
.
licenseUrl
(
licenseUrl
)
.
contact
(
new
Contact
(
contactName
,
contactUrl
,
contactEmail
))
.
build
();
}
// 解决跨域问题
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
.
allowedHeaders
(
"*"
)
.
allowedMethods
(
"*"
)
.
allowedOrigins
(
"*"
);
}
}
\ No newline at end of file
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