Spring加载resource时classpath*:与classpath:的区别:
classpath:只会到你指定的class路径中查找找文件。
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找。
举个简单的例子,在web.xml中是这么定义的:classpath*:META-INF/spring/application-context.xml
那么在META-INF/spring这个文件夹底下的所有application-context.xml都会被加载到上下中,这些包括META-INF/spring文件夹底下的 application-context.xml,META-INF/spring的子文件夹的application-context.xml以及jar中的application-context.xml。
如果在web.xml中定义的是:classpath:META-INF/spring/application-context.xml
那么只有META-INF/spring底下的application-context.xml会被加载到上下文中。
classpath*的使用是为了多个component(最终发布成不同的jar包)并行开发,各自的bean定义文件按照一定的规则:package+filename,而使用这些component的调用者可以把这些文件都加载进来。classpath*的加载使用了classloader的 getResources() 方法,用classpath*需要遍历所有的classpath,所以加载速度是很慢的。