Commit cbfcde0e by KingBoy

添加Swagger自动配置

parent 694925e9
...@@ -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")
......
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;
......
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();
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.kingboy.common.utils.CommonAutoConfiguration
\ No newline at end of file
page.enabled=true
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.kingboy.common.config.page.PageConfig,com.kingboy.common.config.swagger.SwaggerConfig
\ No newline at end of file
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 sign in to comment