classpath*

0,
There is special support for retrieving multiple class path resources with the same name, via the "classpath*" prefix. For example, "classpath*:/beans.xml" will find all beans.xml files in the class path, be it in "classes" directories or in JAR files. This is particularly useful for auto-detecting config files.

1,
Hmm..After reading PathMatchingResourcePatternResolver, it looks like classpath* prefix should work with wildcards in mutliple JARs. My test showed it worked for contexts in WEB/classes, but not with a mix in WEB-INF/classes, and some in JARs in WEB-INF/lib. Maybe a bug?

Just updating this post...
OK - just to clarify after feedback from Juergen. classpath*: and wildcards do work, but not from the root directory within JARs. So for application contexts in the classpath at:

/com/company/applicationContext.xml
/com/company/applicationContext-ds.xml

If they're in WEB-INF/classes the following will work:
classpath*:**/applicationContext*.xml

If they're in a JAR in WEB-INF/lib the following will work:
classpath*:/com/**/applicationContext*.xml

2,
When you use 'classpath:' for an Ant style wildcard search, Spring uses a single classpath directory for the search. The documentation is vague, but it seems the directory returned will be the first one provided by ClassLoader.getResources(""). In our case, it returned the '/target/test-classes' directory that contains applicationTest.xml and our test classes, instead of '/target/classes' which contains application.xml and all the *.hbm.xml files.

Using the 'classpath*:' prefix fixes the problem. It indicates that the resource loader should look in all directories on the classpath, so making this change solved our problem. Apparently Spring maintains both prefixes because limitations in the Classloader (at the specification level) make it difficult to search for resources in the classpath root when performing wildcard searches across all classpath directories. This suggest it might be good practice to always create a directory to contain resources you might otherwise want to put in the classpath root and always use the 'claspath*:' prefix.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值