spring加载资源文件中classpath*与classpath的区别

我们在做Spring和Mbatis集成的时候,需要在配置中配置mapperLocations.
我需要加载多个包下的mapper.xml文件.
比如加载cn/wolfcode/base/mapper文件夹和cn/wolfcode/bussiness/mapper文件夹下所有的mapper.xml文件.
一开始文件配置如下:

  
          
          
          
          
 

结果一直报cn/wolfcode/base/mapper下的mapper文件的某个方法找不到.
错误:Invalid bound statement (not found)

修改成这样就可以找到了.

  
          
          
          
          
 

原因是classpath:和classpath*:在spring加载资源的时候是不同的.

classpath:只能加载找到的匹配的第一个资源目录下文件.(上面只匹配了cn/wolfcode/bussiness/mapper下的mapper文件,而cn/wolfcode/base/mapper就被忽略了)

classpath*:能加载多个路径下的资源目录下文件.(cn/wolfcode/bussiness/mapper和cn/wolfcode/base/mapper中的mapper.xml文件都被加载进来了.)

你可能感兴趣的:(spring加载资源文件中classpath*与classpath的区别)