ibatis与spring的配置( There is no statement named XXX in this SqlMap)

公司的spring+ struts+ ibatis的框架,用得很熟了。想自己写一个demo,可是在spring和ibatis配置的时候,出现了令人纠结的问题。

 

报错提示:  There is no statement named XXX in this SqlMap。

 

其实看字面上的意思就知道是,ibatis的xml配置文件没找到或者xml配置文件出错。但是令人蛋疼的是,公司的项目与demo的配置一模一样,为什么神马会如此让我不堪呢?

 

ibatis与spring的整合配置部分如下:

 

spring配置文件,

[html]  view plain copy
  1. <bean id="sqlMapClient"  
  2.     class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">  
  3.     <property name="configLocation"  
  4.         value="classpath:config/sql-map-config.xml" />  
  5.     <property name="mappingLocations"  
  6.         value="classpath:cn/xiaoqiang/ibatis/sqlmap/*/*.xml" />  
  7.     <property name="dataSource" ref="dataSource" />  
  8. </bean>  


 

sql-map-config.xml,

[html]  view plain copy
  1. <sqlMapConfig>   
  2.     <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true"  
  3.         maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />  
  4. </sqlMapConfig>  


因为公司的项目结构很庞大,故用 mappingLocations 配置ibatis的映射文件,并使用了 * 通配符。这个做法省了些麻烦,就不必要在sql-map-config.xml文件中加入类似于:

 

<sqlMap resource="config/User.xml"/> 的引入映射文件了。

 

但是呢,在我的demo项目中,只有一个ibatis的 User.xml映射文件,基于以上配置,故报了 There is no statement named XXX in this SqlMap 的错误。玛德,让哥蛋疼很

 

久。错误很明显,但又找不出具体原因。只能逐一排查,路径啊、字符少了或是多了、数据源啊等。最后,灵光一现,换一种配置方法,竟然OK了。该方法是: 注释掉spring

 

配置文件中的:

<property name="mappingLocations"  value="classpath:cn/xiaoqiang/ibatis/sqlmap/*/*.xml" /> ,然后在 sql-map-config.xml文件中加入

<sqlMap resource="config/User.xml"/> 。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值