mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-31 19:35:11 +00:00
将swagger拆出来做成可选配置
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
<!--子模块 -->
|
||||
<modules>
|
||||
<module>udf-starter-core</module>
|
||||
<module>udf-starter-swagger2</module>
|
||||
<module>udf-starter-rms</module>
|
||||
<module>udf-starter-cors</module>
|
||||
<module>udf-starter-amqp-rabbitmq</module>
|
||||
@@ -77,6 +78,12 @@
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
<version>${udf-starter.version}</version>
|
||||
</dependency>
|
||||
<!-- udf-starter-swagger2 -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-swagger2</artifactId>
|
||||
<version>${udf-starter.version}</version>
|
||||
</dependency>
|
||||
<!-- udf-starter-rms -->
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-starter-swagger2</artifactId>
|
||||
<name>udf-starter-swagger2</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://itkk.org:81</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.itkk.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+86
-86
@@ -1,86 +1,86 @@
|
||||
/**
|
||||
* Swagger2Config.java
|
||||
* Created at 2016-10-02
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 itkk.org, All rights reserved.
|
||||
*/
|
||||
package org.itkk.udf.core;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
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.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 描述 : 配置api文档
|
||||
*
|
||||
* @author wangkang
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
/**
|
||||
* 描述 : 系统版本
|
||||
*/
|
||||
@Value("${info.build.version}")
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 描述 : 系统名称
|
||||
*/
|
||||
@Value("${info.build.name}")
|
||||
private String projectName;
|
||||
|
||||
/**
|
||||
* 描述 : addResourceHandlers
|
||||
*
|
||||
* @return WebMvcConfigurerAdapter
|
||||
*/
|
||||
@Bean
|
||||
public WebMvcConfigurerAdapter addResourceHandlers() {
|
||||
return new WebMvcConfigurerAdapter() {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("swagger-ui.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : createRestApi
|
||||
*
|
||||
* @return createRestApi
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo()).select()
|
||||
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)).paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : apiInfo
|
||||
*
|
||||
* @return apiInfo
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
|
||||
apiInfoBuilder.title(this.projectName + " online api document");
|
||||
apiInfoBuilder.version(version);
|
||||
return apiInfoBuilder.build();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Swagger2Config.java
|
||||
* Created at 2016-10-02
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 itkk.org, All rights reserved.
|
||||
*/
|
||||
package org.itkk.udf.swagger2;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
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.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 描述 : 配置api文档
|
||||
*
|
||||
* @author wangkang
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
/**
|
||||
* 描述 : 系统版本
|
||||
*/
|
||||
@Value("${info.build.version}")
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 描述 : 系统名称
|
||||
*/
|
||||
@Value("${info.build.name}")
|
||||
private String projectName;
|
||||
|
||||
/**
|
||||
* 描述 : addResourceHandlers
|
||||
*
|
||||
* @return WebMvcConfigurerAdapter
|
||||
*/
|
||||
@Bean
|
||||
public WebMvcConfigurerAdapter addResourceHandlers() {
|
||||
return new WebMvcConfigurerAdapter() {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("swagger-ui.html")
|
||||
.addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : createRestApi
|
||||
*
|
||||
* @return createRestApi
|
||||
*/
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo()).select()
|
||||
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)).paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : apiInfo
|
||||
*
|
||||
* @return apiInfo
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
|
||||
apiInfoBuilder.title(this.projectName + " online api document");
|
||||
apiInfoBuilder.version(version);
|
||||
return apiInfoBuilder.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user