當前位置:
首頁 >
base-package 详解
發布時間:2023/12/14
27
豆豆
生活随笔
收集整理的這篇文章主要介紹了
base-package 详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
spring中 base-package 屬性指定要掃描的基礎包。我們可以在配置中使用匹配符和占位符。
通配符說明:
- ? 匹配一個字符
- * 匹配空或匹配至少一個字符但不包含分割符(默認分割符為‘/’)
- ** 匹配空或匹配至少一個字符可以包含分割符(默認分割符為‘/’)
spring 源碼分析 ClassPathScanningCandidateComponentProvider:
解析步驟:
PathMatchingResourcePatternResolver#findPathMatchingResources 源碼
解析步驟:
注:路徑與subPattern 的匹配是有 AntPathMatcher 類來實現的
對AntPathMatcher的測試:
public static AntPathMatcher ant = new AntPathMatcher();public static void main(String[] args) {test("com*/test", "comaaaa/test"); // truetest("com*/test", "com/test"); // truetest("com**/test", "comaaaa/test"); // truetest("com**/test", "com/test"); // truetest("com**/test", "com/a/test"); // falsetest("com/*/test", "com/test"); // falsetest("com/*/test", "com/a/test"); // truetest("com/*/test", "com/a/b/test"); // falsetest("com/**/test", "com/test"); // truetest("com/**/test", "com/a/test"); // true test("com/**/test", "com/a/b/test");// true }public static void test(String pattern, String text) {System.out.println(String.format("%s => %s : %s", pattern, text, ant.match(pattern, text)));}總結
以上是生活随笔為你收集整理的base-package 详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 64位程序使用ado连接oracle,3
- 下一篇: 04-如何选购台式电脑显卡?小白装机通俗