提交 a6da9a34 编写于 作者: M mxd

兼容`spring-boot 2.6.0`

上级 c830c9c4
......@@ -274,13 +274,13 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
// 配置静态资源路径
registry.addResourceHandler(web + "/**").addResourceLocations("classpath:/magic-editor/");
try {
Mapping.create(requestMappingHandlerMapping)
Mapping mapping = Mapping.create(requestMappingHandlerMapping);
// 默认首页设置
.register(RequestMappingInfo.paths(web).build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("redirectIndex", HttpServletRequest.class))
mapping.register(mapping.paths(web).build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("redirectIndex", HttpServletRequest.class))
// 读取配置
.register(RequestMappingInfo.paths(web + "/config.json").build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("readConfig"))
.register(mapping.paths(web + "/config.json").build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("readConfig"))
// 读取配置
.register(RequestMappingInfo.paths(web + "/classes.txt").produces("text/plain").build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("readClass"));
.register(mapping.paths(web + "/classes.txt").produces("text/plain").build(), this, MagicAPIAutoConfiguration.class.getDeclaredMethod("readClass"));
} catch (NoSuchMethodException ignored) {
}
}
......@@ -583,9 +583,10 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
}
// 注册接收推送的接口
if (StringUtils.isNotBlank(properties.getSecretKey())) {
RequestMappingInfo requestMappingInfo = RequestMappingInfo.paths(properties.getPushPath()).build();
Mapping mapping = Mapping.create(requestMappingHandlerMapping);
RequestMappingInfo requestMappingInfo = mapping.paths(properties.getPushPath()).build();
Method method = MagicWorkbenchController.class.getDeclaredMethod("receivePush", MultipartFile.class, String.class, Long.class, String.class);
Mapping.create(requestMappingHandlerMapping).register(requestMappingInfo, magicWorkbenchController, method);
mapping.register(requestMappingInfo, magicWorkbenchController, method);
}
// 注册数据源
magicAPIService.registerAllDataSource();
......
......@@ -51,7 +51,8 @@ public class MagicSwaggerConfiguration {
@Primary
public SwaggerResourcesProvider magicSwaggerResourcesProvider(MappingHandlerMapping handlerMapping, GroupServiceProvider groupServiceProvider, ServletContext servletContext) throws NoSuchMethodException {
SwaggerConfig config = properties.getSwaggerConfig();
RequestMappingInfo requestMappingInfo = RequestMappingInfo.paths(config.getLocation()).build();
Mapping mapping = Mapping.create(requestMappingHandlerMapping);
RequestMappingInfo requestMappingInfo = mapping.paths(config.getLocation()).build();
// 构建文档信息
SwaggerProvider swaggerProvider = new SwaggerProvider();
......@@ -64,7 +65,7 @@ public class MagicSwaggerConfiguration {
// 注册swagger.json
Mapping.create(requestMappingHandlerMapping).register(requestMappingInfo, swaggerProvider, SwaggerProvider.class.getDeclaredMethod("swaggerJson"));
mapping.register(requestMappingInfo, swaggerProvider, SwaggerProvider.class.getDeclaredMethod("swaggerJson"));
return () -> {
List<SwaggerResource> resources = new ArrayList<>();
......
......@@ -8,7 +8,6 @@ import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.ssssssss.magicapi.adapter.Resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
......@@ -98,7 +97,7 @@ public class RedisResource extends KeyValueResource {
@Override
protected Set<String> keys() {
Set<String> keys = this.redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
ScanOptions options = new ScanOptions.ScanOptionsBuilder()
ScanOptions options = ScanOptions.scanOptions()
.count(Long.MAX_VALUE)
.match((isDirectory() ? this.path : (this.path + separator)) + "*")
.build();
......@@ -107,7 +106,7 @@ public class RedisResource extends KeyValueResource {
while (cursor.hasNext()) {
returnKeys.add(new String(cursor.next()));
}
} catch (IOException e) {
} catch (Exception e) {
logger.error("扫描key出错", e);
}
return returnKeys;
......
......@@ -442,7 +442,7 @@ public class MappingHandlerMapping {
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
if (requestMapping != null) {
String[] paths = Stream.of(requestMapping.value()).map(value -> base + value).toArray(String[]::new);
mappingHelper.register(RequestMappingInfo.paths(paths).build(), target, method);
mappingHelper.register(mappingHelper.paths(paths).build(), target, method);
}
}
}
......@@ -479,14 +479,14 @@ public class MappingHandlerMapping {
* 根据接口信息构建 RequestMappingInfo
*/
private RequestMappingInfo getRequestMapping(ApiInfo info) {
return RequestMappingInfo.paths(getRequestPath(info.getGroupId(), info.getPath())).methods(RequestMethod.valueOf(info.getMethod().toUpperCase())).build();
return mappingHelper.paths(getRequestPath(info.getGroupId(), info.getPath())).methods(RequestMethod.valueOf(info.getMethod().toUpperCase())).build();
}
/**
* 根据接口信息构建 RequestMappingInfo
*/
private RequestMappingInfo getRequestMapping(String method, String path) {
return RequestMappingInfo.paths(path).methods(RequestMethod.valueOf(method.toUpperCase())).build();
return mappingHelper.paths(path).methods(RequestMethod.valueOf(method.toUpperCase())).build();
}
static class MappingNode {
......
......@@ -3,7 +3,7 @@ package org.ssssssss.magicapi.utils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import java.lang.reflect.Method;
import java.util.Map;
......@@ -17,12 +17,27 @@ public class Mapping {
private final AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping;
private Mapping(AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping) {
private RequestMappingInfo.BuilderConfiguration config;
private Mapping(AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping, RequestMappingInfo.BuilderConfiguration config) {
this.methodMapping = methodMapping;
this.config = config;
}
public static Mapping create(RequestMappingHandlerMapping mapping) {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
config.setTrailingSlashMatch(mapping.useTrailingSlashMatch());
config.setContentNegotiationManager(mapping.getContentNegotiationManager());
if (mapping.getPatternParser() != null) {
config.setPatternParser(mapping.getPatternParser());
} else {
config.setPathMatcher(mapping.getPathMatcher());
}
return new Mapping(mapping, config);
}
public static Mapping create(RequestMappingInfoHandlerMapping mapping) {
return new Mapping(mapping);
public RequestMappingInfo.Builder paths(String ... paths){
return RequestMappingInfo.paths(paths).options(this.config);
}
public Mapping register(RequestMappingInfo requestMappingInfo, Object handler, Method method) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册