增加 swagger starter
This commit is contained in:
parent
220984c45b
commit
57145d426e
@ -11,18 +11,6 @@
|
|||||||
|
|
||||||
<artifactId>common-framework</artifactId>
|
<artifactId>common-framework</artifactId>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>common-dependencies</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Web 相关 -->
|
<!-- Web 相关 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
33
common/mall-spring-boot-starter-swagger/pom.xml
Normal file
33
common/mall-spring-boot-starter-swagger/pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>common</artifactId>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mall-spring-boot-starter-swagger</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spring 核心 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Web 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,57 @@
|
|||||||
|
package cn.iocoder.mall.swagger.config;
|
||||||
|
|
||||||
|
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 简单的 Swagger2 自动配置类
|
||||||
|
*
|
||||||
|
* 较为完善的,可以了解 https://mvnrepository.com/artifact/com.spring4all/spring-boot-starter-swagger
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
@EnableKnife4j
|
||||||
|
@ConditionalOnClass({Docket.class, ApiInfoBuilder.class})
|
||||||
|
@ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true) // 允许使用 swagger.enable=false 禁用 Swagger
|
||||||
|
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||||
|
public class SwaggerAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public SwaggerProperties swaggerProperties() {
|
||||||
|
return new SwaggerProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket createRestApi() {
|
||||||
|
SwaggerProperties properties = swaggerProperties();
|
||||||
|
// 创建 Docket 对象
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.apiInfo(apiInfo(properties))
|
||||||
|
.select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage(properties.getBasePackage()))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo apiInfo(SwaggerProperties properties) {
|
||||||
|
return new ApiInfoBuilder()
|
||||||
|
.title(properties.getTitle())
|
||||||
|
.description(properties.getDescription())
|
||||||
|
.version(properties.getVersion())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package cn.iocoder.mall.swagger.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties("swagger")
|
||||||
|
public class SwaggerProperties {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String version;
|
||||||
|
private String basePackage;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwaggerProperties setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwaggerProperties setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwaggerProperties setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBasePackage() {
|
||||||
|
return basePackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SwaggerProperties setBasePackage(String basePackage) {
|
||||||
|
this.basePackage = basePackage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.mall.swagger;
|
@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
cn.iocoder.mall.swagger.config.SwaggerAutoConfiguration
|
@ -26,6 +26,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|||||||
@ConditionalOnClass({Docket.class, ApiInfoBuilder.class})
|
@ConditionalOnClass({Docket.class, ApiInfoBuilder.class})
|
||||||
@ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true) // 允许使用 swagger.enable=false 禁用 Swagger
|
@ConditionalOnProperty(prefix = "swagger", value = "enable", matchIfMissing = true) // 允许使用 swagger.enable=false 禁用 Swagger
|
||||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||||
|
@Deprecated
|
||||||
public class SwaggerAutoConfiguration {
|
public class SwaggerAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ConfigurationProperties("swagger")
|
@ConfigurationProperties("swagger")
|
||||||
|
@Deprecated
|
||||||
public class SwaggerProperties {
|
public class SwaggerProperties {
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
@ -15,7 +15,19 @@
|
|||||||
<module>common-framework</module>
|
<module>common-framework</module>
|
||||||
<module>mall-spring-boot</module>
|
<module>mall-spring-boot</module>
|
||||||
<module>common-dependencies</module>
|
<module>common-dependencies</module>
|
||||||
|
<module>mall-spring-boot-starter-swagger</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>mall-dependencies</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
92
mall-dependencies/pom.xml
Normal file
92
mall-dependencies/pom.xml
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>onemall</artifactId>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mall-dependencies</artifactId>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>Onemall Dependencies</name>
|
||||||
|
<description>Maven Bom,定义 Onemall 项目的所有依赖的版本</description>
|
||||||
|
|
||||||
|
<!-- 属性 -->
|
||||||
|
<properties>
|
||||||
|
<!-- TODO Spring Boot && Spring Cloud && Spring Cloud Alibaba -->
|
||||||
|
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||||
|
<spring.cloud.version>Hoxton.SR1</spring.cloud.version>
|
||||||
|
<spring.cloud.alibaba.version>2.2.0.RELEASE</spring.cloud.alibaba.version>
|
||||||
|
<!-- Web 相关 -->
|
||||||
|
<knife4j.version>2.0.2</knife4j.version>
|
||||||
|
<!-- RPC 相关 -->
|
||||||
|
<dubbo.version>2.7.1</dubbo.version>
|
||||||
|
<!-- Transaction 相关 -->
|
||||||
|
<seata.version>1.1.0</seata.version>
|
||||||
|
<!-- 监控相关 -->
|
||||||
|
<skywalking.version>7.0.0</skywalking.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<!-- 依赖管理 -->
|
||||||
|
<dependencyManagement>
|
||||||
|
<!-- TODO Spring Boot && Spring Cloud && Spring Cloud Alibaba -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>${spring.boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>${spring.cloud.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>${spring.cloud.alibaba.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Web 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
|
<version>${knife4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RPC 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.dubbo</groupId>
|
||||||
|
<artifactId>dubbo</artifactId>
|
||||||
|
<version>${dubbo.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Transaction 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.seata</groupId>
|
||||||
|
<artifactId>seata-spring-boot-starter</artifactId>
|
||||||
|
<version>${seata.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 监控相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.skywalking</groupId>
|
||||||
|
<artifactId>apm-toolkit-trace</artifactId>
|
||||||
|
<version>${skywalking.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
</project>
|
1
pom.xml
1
pom.xml
@ -24,6 +24,7 @@
|
|||||||
<module>promotion</module>
|
<module>promotion</module>
|
||||||
<module>search</module>
|
<module>search</module>
|
||||||
<module>demo</module>
|
<module>demo</module>
|
||||||
|
<module>mall-dependencies</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@ public interface ProductSpuConvert {
|
|||||||
})
|
})
|
||||||
ProductSpuBO convert(ProductSpuDO spu);
|
ProductSpuBO convert(ProductSpuDO spu);
|
||||||
|
|
||||||
|
@Named("translatePicUrlsFromString")
|
||||||
|
default List<String> translatePicUrlsFromString(String picUrls) {
|
||||||
|
return StringUtil.split(picUrls, ",");
|
||||||
|
}
|
||||||
|
|
||||||
@Mappings({})
|
@Mappings({})
|
||||||
List<ProductSpuBO> convert(List<ProductSpuDO> spus);
|
List<ProductSpuBO> convert(List<ProductSpuDO> spus);
|
||||||
|
|
||||||
@ -125,9 +130,6 @@ public interface ProductSpuConvert {
|
|||||||
return spuDetailList;
|
return spuDetailList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Named("translatePicUrlsFromString")
|
|
||||||
default List<String> translatePicUrlsFromString(String picUrls) {
|
|
||||||
return StringUtil.split(picUrls, ",");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>system-application</module>
|
<module>system-application</module>
|
||||||
<module>system-sdk</module>
|
<module>system-sdk</module>
|
||||||
<module>system-service-api</module>
|
<!-- <module>system-service-api</module>-->
|
||||||
<module>system-service-impl</module>
|
<!-- <module>system-service-impl</module>-->
|
||||||
<module>system-rpc-api</module>
|
<module>system-rpc-api</module>
|
||||||
<module>system-rpc</module>
|
<module>system-rpc</module>
|
||||||
<module>system-rest</module>
|
<module>system-rest</module>
|
||||||
|
@ -25,15 +25,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- TODO 实现自己的 starter -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>mall-spring-boot-starter-swagger</artifactId>
|
||||||
</dependency>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
|
||||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -3,3 +3,10 @@ server:
|
|||||||
port: 18083
|
port: 18083
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /system-api/
|
context-path: /system-api/
|
||||||
|
|
||||||
|
# Swagger 配置项
|
||||||
|
swagger:
|
||||||
|
title: 管理员子系统
|
||||||
|
description: 管理员子系统
|
||||||
|
version: 1.0.0
|
||||||
|
base-package: cn.iocoder.mall.system.rest.controller
|
||||||
|
Loading…
Reference in New Issue
Block a user