diff --git a/core/src/main/java/com/usthe/sureness/matcher/PathTreeProvider.java b/core/src/main/java/com/usthe/sureness/matcher/PathTreeProvider.java index 9fe11cee..8fa2ea7b 100644 --- a/core/src/main/java/com/usthe/sureness/matcher/PathTreeProvider.java +++ b/core/src/main/java/com/usthe/sureness/matcher/PathTreeProvider.java @@ -16,7 +16,7 @@ public interface PathTreeProvider { * eg: springboot context path is: server.servlet.context-path = v2 * tomcat context path is: */ - AtomicReference contextPathRef = new AtomicReference(); + AtomicReference CONTEXT_PATH_REF = new AtomicReference<>(); /** * set context path @@ -24,7 +24,16 @@ public interface PathTreeProvider { * @param contextPath context path */ default void setContextPath(String contextPath) { - contextPathRef.set(contextPath); + CONTEXT_PATH_REF.set(contextPath); + } + + /** + * get context path + * Please sync with your server context path settings use setContextPath + * @return context path + */ + default String getContextPath() { + return CONTEXT_PATH_REF.get(); } /** diff --git a/core/src/main/java/com/usthe/sureness/provider/annotation/AnnotationPathTreeProvider.java b/core/src/main/java/com/usthe/sureness/provider/annotation/AnnotationPathTreeProvider.java index 6b1d3adf..8a4a8d9a 100644 --- a/core/src/main/java/com/usthe/sureness/provider/annotation/AnnotationPathTreeProvider.java +++ b/core/src/main/java/com/usthe/sureness/provider/annotation/AnnotationPathTreeProvider.java @@ -77,7 +77,7 @@ public Set providePathData() { } } } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resource); + return SurenessCommonUtil.attachContextPath(getContextPath(), resource); } @Override @@ -100,7 +100,7 @@ public Set provideExcludedResource() { } } } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resource); + return SurenessCommonUtil.attachContextPath(getContextPath(), resource); } public List getScanPackages() { diff --git a/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentPathTreeProvider.java b/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentPathTreeProvider.java index 37b40aaf..c494ec08 100644 --- a/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentPathTreeProvider.java +++ b/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentPathTreeProvider.java @@ -35,7 +35,7 @@ public Set providePathData() { } else { resourceSet = new HashSet<>(); } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceSet); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceSet); } catch (IOException e) { logger.error("load config data from yaml file error: ", e); throw new SurenessLoadDataException(e.getMessage()); @@ -55,7 +55,7 @@ public Set provideExcludedResource() { } else { resourceSet = new HashSet<>(); } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceSet); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceSet); } catch (IOException e) { logger.error("load config data from yaml file error: ", e); throw new SurenessLoadDataException(e.getMessage()); diff --git a/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java b/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java index 8fe57099..9de8e097 100644 --- a/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java +++ b/core/src/main/java/com/usthe/sureness/provider/ducument/DocumentResourceDefaultProvider.java @@ -50,7 +50,7 @@ public Set providePathData() { } else { resourceSet = new HashSet<>(); } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceSet); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceSet); } catch (IOException e) { logger.error("load config data from yaml file error: ", e); throw new SurenessLoadDataException(e.getMessage()); @@ -70,7 +70,7 @@ public Set provideExcludedResource() { } else { resourceSet = new HashSet<>(); } - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceSet); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceSet); } catch (IOException e) { logger.error("load config data from yaml file error: ", e); throw new SurenessLoadDataException(e.getMessage()); diff --git a/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabasePathTreeProvider.java b/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabasePathTreeProvider.java index d84d523e..7026474c 100644 --- a/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabasePathTreeProvider.java +++ b/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabasePathTreeProvider.java @@ -22,13 +22,13 @@ public class DatabasePathTreeProvider implements PathTreeProvider { @Override public Set providePathData() { - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceService.getAllEnableResourcePath()); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceService.getAllEnableResourcePath()); } @Override public Set provideExcludedResource() { - return SurenessCommonUtil.attachContextPath(contextPathRef.get(), resourceService.getAllDisableResourcePath()); + return SurenessCommonUtil.attachContextPath(getContextPath(), resourceService.getAllDisableResourcePath()); } }