解决由于ControllerMethodsCache类的getMethod方法中,由于replace target写死造成的修改contextPath后找不到api的异常

This commit is contained in:
wanyuyichen 2020-05-07 17:19:58 +08:00
parent 4baaef4b5a
commit 071be5c3d4

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.core.code;
import org.apache.commons.lang3.ArrayUtils;
import org.reflections.Reflections;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
@ -35,6 +36,9 @@ import java.util.concurrent.ConcurrentMap;
@Component
public class ControllerMethodsCache {
@Value("${server.servlet.contextPath:/nacos}")
private String contextPath;
private ConcurrentMap<String, Method> methods = new
ConcurrentHashMap<>();
@ -43,7 +47,7 @@ public class ControllerMethodsCache {
}
public Method getMethod(String httpMethod, String path) {
String key = httpMethod + "-->" + path.replace("/nacos", "");
String key = httpMethod + "-->" + path.replace(contextPath, "");
return methods.get(key);
}