Swagger改用Starter
This commit is contained in:
@@ -2,6 +2,8 @@ package com.macro.mall.config;
|
|||||||
|
|
||||||
import com.macro.mall.common.config.BaseSwaggerConfig;
|
import com.macro.mall.common.config.BaseSwaggerConfig;
|
||||||
import com.macro.mall.common.domain.SwaggerProperties;
|
import com.macro.mall.common.domain.SwaggerProperties;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
@@ -24,4 +26,10 @@ public class SwaggerConfig extends BaseSwaggerConfig {
|
|||||||
.enableSecurity(true)
|
.enableSecurity(true)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
||||||
|
return generateBeanPostProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ spring:
|
|||||||
multipart:
|
multipart:
|
||||||
enabled: true #开启文件上传
|
enabled: true #开启文件上传
|
||||||
max-file-size: 10MB #限制文件上传大小为10M
|
max-file-size: 10MB #限制文件上传大小为10M
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
@@ -30,15 +33,15 @@ redis:
|
|||||||
secure:
|
secure:
|
||||||
ignored:
|
ignored:
|
||||||
urls: #安全路径白名单
|
urls: #安全路径白名单
|
||||||
- /swagger-ui.html
|
- /swagger-ui/
|
||||||
- /swagger-resources/**
|
- /swagger-resources/**
|
||||||
- /swagger/**
|
|
||||||
- /**/v2/api-docs
|
- /**/v2/api-docs
|
||||||
|
- /**/*.html
|
||||||
- /**/*.js
|
- /**/*.js
|
||||||
- /**/*.css
|
- /**/*.css
|
||||||
- /**/*.png
|
- /**/*.png
|
||||||
- /**/*.ico
|
- /**/*.map
|
||||||
- /webjars/springfox-swagger-ui/**
|
- /favicon.ico
|
||||||
- /actuator/**
|
- /actuator/**
|
||||||
- /druid/**
|
- /druid/**
|
||||||
- /admin/login
|
- /admin/login
|
||||||
@@ -59,9 +62,3 @@ aliyun:
|
|||||||
callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址
|
callback: http://39.98.190.128:8080/aliyun/oss/callback # 文件上传成功后的回调地址
|
||||||
dir:
|
dir:
|
||||||
prefix: mall/images/ # 上传文件夹路径前缀
|
prefix: mall/images/ # 上传文件夹路径前缀
|
||||||
|
|
||||||
minio:
|
|
||||||
endpoint: http://192.168.3.101:9090 #MinIO服务所在地址
|
|
||||||
bucketName: mall #存储桶名称
|
|
||||||
accessKey: minioadmin #访问的key
|
|
||||||
secretKey: minioadmin #访问的秘钥
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.macro.mall.common.config;
|
package com.macro.mall.common.config;
|
||||||
|
|
||||||
import com.macro.mall.common.domain.SwaggerProperties;
|
import com.macro.mall.common.domain.SwaggerProperties;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.PathSelectors;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
@@ -9,9 +13,13 @@ import springfox.documentation.service.*;
|
|||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
||||||
|
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swagger基础配置
|
* Swagger基础配置
|
||||||
@@ -43,9 +51,9 @@ public abstract class BaseSwaggerConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ApiKey> securitySchemes() {
|
private List<SecurityScheme> securitySchemes() {
|
||||||
//设置请求头信息
|
//设置请求头信息
|
||||||
List<ApiKey> result = new ArrayList<>();
|
List<SecurityScheme> result = new ArrayList<>();
|
||||||
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
|
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
|
||||||
result.add(apiKey);
|
result.add(apiKey);
|
||||||
return result;
|
return result;
|
||||||
@@ -74,6 +82,38 @@ public abstract class BaseSwaggerConfig {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BeanPostProcessor generateBeanPostProcessor(){
|
||||||
|
return new BeanPostProcessor() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||||
|
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
||||||
|
customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
|
||||||
|
List<T> copy = mappings.stream()
|
||||||
|
.filter(mapping -> mapping.getPatternParser() == null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
mappings.clear();
|
||||||
|
mappings.addAll(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
|
||||||
|
try {
|
||||||
|
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
||||||
|
field.setAccessible(true);
|
||||||
|
return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义Swagger配置
|
* 自定义Swagger配置
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.macro.mall.demo.config;
|
|||||||
|
|
||||||
import com.macro.mall.common.config.BaseSwaggerConfig;
|
import com.macro.mall.common.config.BaseSwaggerConfig;
|
||||||
import com.macro.mall.common.domain.SwaggerProperties;
|
import com.macro.mall.common.domain.SwaggerProperties;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
@@ -25,4 +27,9 @@ public class SwaggerConfig extends BaseSwaggerConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
||||||
|
return generateBeanPostProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: mall-demo
|
name: mall-demo
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
@@ -14,6 +14,10 @@ spring:
|
|||||||
servlet:
|
servlet:
|
||||||
content-type: text/html
|
content-type: text/html
|
||||||
cache: false #开发时关闭缓存,不然没法看到实时页面
|
cache: false #开发时关闭缓存,不然没法看到实时页面
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
- classpath:mapper/*.xml
|
- classpath:mapper/*.xml
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.macro.mall.portal.config;
|
|||||||
|
|
||||||
import com.macro.mall.common.config.BaseSwaggerConfig;
|
import com.macro.mall.common.config.BaseSwaggerConfig;
|
||||||
import com.macro.mall.common.domain.SwaggerProperties;
|
import com.macro.mall.common.domain.SwaggerProperties;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
@@ -24,4 +26,9 @@ public class SwaggerConfig extends BaseSwaggerConfig {
|
|||||||
.enableSecurity(true)
|
.enableSecurity(true)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
||||||
|
return generateBeanPostProcessor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ spring:
|
|||||||
name: mall-portal
|
name: mall-portal
|
||||||
profiles:
|
profiles:
|
||||||
active: dev #默认为开发环境
|
active: dev #默认为开发环境
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
@@ -18,15 +21,15 @@ jwt:
|
|||||||
secure:
|
secure:
|
||||||
ignored:
|
ignored:
|
||||||
urls: #安全路径白名单
|
urls: #安全路径白名单
|
||||||
- /swagger-ui.html
|
- /swagger-ui/
|
||||||
- /swagger-resources/**
|
- /swagger-resources/**
|
||||||
- /swagger/**
|
|
||||||
- /**/v2/api-docs
|
- /**/v2/api-docs
|
||||||
|
- /**/*.html
|
||||||
- /**/*.js
|
- /**/*.js
|
||||||
- /**/*.css
|
- /**/*.css
|
||||||
- /**/*.png
|
- /**/*.png
|
||||||
- /**/*.ico
|
- /**/*.map
|
||||||
- /webjars/springfox-swagger-ui/**
|
- /favicon.ico
|
||||||
- /druid/**
|
- /druid/**
|
||||||
- /actuator/**
|
- /actuator/**
|
||||||
- /sso/**
|
- /sso/**
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.macro.mall.search.config;
|
|||||||
|
|
||||||
import com.macro.mall.common.config.BaseSwaggerConfig;
|
import com.macro.mall.common.config.BaseSwaggerConfig;
|
||||||
import com.macro.mall.common.domain.SwaggerProperties;
|
import com.macro.mall.common.domain.SwaggerProperties;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
@@ -24,4 +26,9 @@ public class SwaggerConfig extends BaseSwaggerConfig {
|
|||||||
.enableSecurity(false)
|
.enableSecurity(false)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
||||||
|
return generateBeanPostProcessor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ spring:
|
|||||||
name: mall-search
|
name: mall-search
|
||||||
profiles:
|
profiles:
|
||||||
active: dev #默认为开发环境
|
active: dev #默认为开发环境
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant_path_matcher
|
||||||
|
|
||||||
server:
|
server:
|
||||||
port: 8081
|
port: 8081
|
||||||
|
|||||||
Reference in New Issue
Block a user