Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
cloud-phantom
/
common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cbfcde0e
authored
Nov 20, 2017
by
KingBoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加Swagger自动配置
parent
694925e9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
8 deletions
+67
-8
build.gradle
+3
-0
src/main/java/com/kingboy/common/config/page/PageConfig.java
+3
-3
src/main/java/com/kingboy/common/config/swagger/SwaggerConfig.java
+58
-0
src/main/java/resources/META-INF/spring.factories
+0
-3
src/main/java/resources/application.properties
+0
-2
src/main/resources/META-INF/spring.factories
+3
-0
src/main/resources/application.properties
+0
-0
No files found.
build.gradle
View file @
cbfcde0e
...
@@ -27,10 +27,13 @@ ext {
...
@@ -27,10 +27,13 @@ ext {
orikaVersion
=
'1.5.2'
orikaVersion
=
'1.5.2'
fastJsonVersion
=
'1.2.41'
fastJsonVersion
=
'1.2.41'
lombokVersion
=
'1.16.18'
lombokVersion
=
'1.16.18'
swaggerVersion
=
'2.7.0'
}
}
dependencies
{
dependencies
{
compile
(
"org.springframework.boot:spring-boot-autoconfigure"
)
compile
(
"org.springframework.boot:spring-boot-autoconfigure"
)
compile
(
"io.springfox:springfox-swagger-ui:${swaggerVersion}"
)
compile
(
"io.springfox:springfox-swagger2:${swaggerVersion}"
)
compile
(
"ma.glasnost.orika:orika-core:$orikaVersion"
)
compile
(
"ma.glasnost.orika:orika-core:$orikaVersion"
)
compile
(
"org.projectlombok:lombok:$lombokVersion"
)
compile
(
"org.projectlombok:lombok:$lombokVersion"
)
compile
(
"com.alibaba:fastjson:$fastJsonVersion"
)
compile
(
"com.alibaba:fastjson:$fastJsonVersion"
)
...
...
src/main/java/com/kingboy/common/
utils/CommonAutoConfiguration
.java
→
src/main/java/com/kingboy/common/
config/page/PageConfig
.java
View file @
cbfcde0e
package
com
.
kingboy
.
common
.
utils
;
package
com
.
kingboy
.
common
.
config
.
page
;
import
com.kingboy.common.utils.page.PageResultFactory
;
import
com.kingboy.common.utils.page.PageResultFactory
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
...
@@ -14,11 +14,11 @@ import org.springframework.context.annotation.Configuration;
...
@@ -14,11 +14,11 @@ import org.springframework.context.annotation.Configuration;
*/
*/
@Configuration
@Configuration
@ConditionalOnClass
({
PageResultFactory
.
class
})
@ConditionalOnClass
({
PageResultFactory
.
class
})
public
class
CommonAutoConfiguration
{
public
class
PageConfig
{
@Bean
@Bean
@ConditionalOnMissingBean
(
PageResultFactory
.
class
)
@ConditionalOnMissingBean
(
PageResultFactory
.
class
)
@ConditionalOnProperty
(
name
=
"page.enabled"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
name
=
"
king.
page.enabled"
,
matchIfMissing
=
true
)
public
PageResultFactory
authorResolver
()
{
public
PageResultFactory
authorResolver
()
{
PageResultFactory
pageResultFactory
=
new
PageResultFactory
();
PageResultFactory
pageResultFactory
=
new
PageResultFactory
();
return
pageResultFactory
;
return
pageResultFactory
;
...
...
src/main/java/com/kingboy/common/config/swagger/SwaggerConfig.java
0 → 100644
View file @
cbfcde0e
package
com
.
kingboy
.
common
.
config
.
swagger
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
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
springfox.documentation.swagger2.web.Swagger2Controller
;
/**
* @author kingboy--KingBoyWorld@163.com
* @date 2017/11/20 下午7:19
* @desc Swagger配置.
*/
@Data
@Configuration
@EnableSwagger2
@ConfigurationProperties
(
prefix
=
"king.swagger"
)
@ConditionalOnProperty
(
name
=
"king.swagger.enabled"
,
havingValue
=
"true"
)
@ConditionalOnClass
(
value
=
Swagger2Controller
.
class
)
public
class
SwaggerConfig
{
private
String
basePackage
=
"com.kingboy.controller"
;
private
String
title
=
"他很懒什么都没有留下"
;
private
String
description
=
"他很懒什么都没有留下"
;
private
String
version
=
"V1.0"
;
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
basePackage
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
title
)
.
description
(
description
)
.
version
(
version
)
.
build
();
}
}
src/main/java/resources/META-INF/spring.factories
deleted
100644 → 0
View file @
694925e9
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.kingboy.common.utils.CommonAutoConfiguration
\ No newline at end of file
src/main/java/resources/application.properties
deleted
100644 → 0
View file @
694925e9
page.enabled
=
true
\ No newline at end of file
src/main/resources/META-INF/spring.factories
0 → 100644
View file @
cbfcde0e
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.kingboy.common.config.page.PageConfig,com.kingboy.common.config.swagger.SwaggerConfig
\ No newline at end of file
src/main/resources/application.properties
0 → 100644
View file @
cbfcde0e
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