4.4.1  使用路径通配符加载Resource

       前面介绍的资源路径都是非常简单的一个路径匹配一个资源,Spring还提供了一种更强大的Ant模式通配符匹配,从能一个路径匹配一批资源。

 

       Ant路径通配符支持“?”、“*”、“**”,注意通配符匹配不包括目录分隔符“/”:

 

         “?”:匹配一个字符,如“config?.xml”将匹配“config1.xml”;

         “*”:匹配零个或多个字符串,如“cn/*/config.xml”将匹配“cn/javass/config.xml”,但不匹配匹配“cn/config.xml”;而“cn/config-*.xml”将匹配“cn/config-dao.xml”;

         “**”:匹配路径中的零个或多个目录,如“cn/**/config.xml”将匹配“cn /config.xml”,也匹配“cn/javass/spring/config.xml”;而“cn/javass/config-**.xml”将匹配“cn/javass/config-dao.xml”,即把“**”当做两个“*”处理。

 

Spring提供AntPathMatcher来进行Ant风格的路径匹配。具体测试请参考cn.javass.spring.chapter4. AntPathMatcherTest。

 

Spring在加载类路径资源时除了提供前缀“classpath:”的来支持加载一个Resource,还提供一个前缀“classpath*:”来支持加载所有匹配的类路径Resource。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
猜你喜欢
  • 2021-11-12
  • 2021-07-26
  • 2022-02-04
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
相关资源
相似解决方案