springmvc+mybatis+mysql.我想配置mapper路径向下面这样。不用每次新建了一个 xml文件就添加一个。但是系统启动的时候报 Could not find resource cn/com/vobile/**/*_sqlmap_mysql.xml错误
<mappers>
<mapper resource="cn/com/vobile/**/*_sqlmap_mysql.xml" />
</mappers>
关于通用匹配是spring提供的ant匹配法,mybatis 没有这个功能。具体实现见:
AntPathMatcher
<mappers>
<mapper resource="cn/com/vobile/**/*_sqlmap_mysql.xml" />
</mappers>
怎么解决?
回答:
你的那个不能使用统配(ant匹配模式)。
例子:文档
1
2
3
4
|
<
bean
id
=
"sqlSessionFactory"
class
=
"org.mybatis.spring.SqlSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"mapperLocations"
value
=
"classpath*:sample/config/mappers/**/*.xml"
/>
</
bean
>
|
例子如下:
public class AntPathMatcher extends Object implements PathMatcher
PathMatcher
implementation for Ant-style path patterns.
Part of this mapping code has been kindly borrowed from Apache Ant.
The mapping matches URLs using the following rules:
?
matches one character*
matches zero or more characters**
matches zero or more directories in a path{spring:[a-z]+}
matches the regexp[a-z]+
as a path variable named "spring"
Examples
com/t?st.jsp
— matchescom/test.jsp
but alsocom/tast.jsp
orcom/txst.jsp
com/*.jsp
— matches all.jsp
files in thecom
directorycom/**/test.jsp
— matches alltest.jsp
files underneath thecom
pathorg/springframework/**/*.jsp
— matches all.jsp
files underneath theorg/springframework
pathorg/**/servlet/bla.jsp
— matchesorg/springframework/servlet/bla.jsp
but alsoorg/springframework/testing/servlet/bla.jsp
andorg/servlet/bla.jsp
com/{filename:\\w+}.jsp
will matchcom/test.jsp
and assign the valuetest
to thefilename
variable