From c2e406edcc4c6e8eaf5d639ef0f0bcb717bcc86e Mon Sep 17 00:00:00 2001 From: tanghc Date: Wed, 7 Aug 2019 10:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontext-path=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/ServiceZookeeperApiMetaManager.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java index 04e4d21d..191b8e54 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java @@ -37,6 +37,8 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager { private static final String PATH_SPLIT = "/"; + private static final String DEFAULT_CONTEXT_PATH = "/"; + private Environment environment; private ZookeeperTool zookeeperTool; @@ -146,14 +148,13 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager { } protected String buildServletPath(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) { + String contextPath = environment.getProperty("server.servlet.context-path", DEFAULT_CONTEXT_PATH); String servletPath = apiMeta.getPath(); if (servletPath == null) { servletPath = ""; } - if (!servletPath.startsWith(PATH_SPLIT)) { - servletPath = PATH_SPLIT + servletPath; - } - return servletPath; + StringUtils.trimLeadingCharacter(servletPath, '/'); + return contextPath + servletPath; } /**