我在Scala中有一个使用mybatis-scala和spring的webapp。该应用程序工作正常,但当我向ContextLoaderListener
添加web.xml
时(因为我需要配置弹簧安全性),我开始收到以下错误:
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ...
Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ...
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:94)
at org.mybatis.scala.session.Session.selectList(Session.scala:45)
at org.mybatis.scala.mapping.SelectList$$anonfun$apply$1.apply(Select.scala:81)
at org.mybatis.scala.mapping.SelectList$$anonfun$apply$1.apply(Select.scala:81)
at org.mybatis.scala.mapping.Statement$class.execute(Statement.scala:81)
at org.mybatis.scala.mapping.SelectList.execute(Select.scala:73)
at org.mybatis.scala.mapping.SelectList.apply(Select.scala:81)
我混合xml和基于scala的配置。在我的web.xml
我有:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml
/WEB-INF/security.xml
</param-value>
</context-param>
然后在mvc-dispatcher-servlet.xml
以及我使用的其他内容
<context:annotation-config/>
MyBatis配置以一种谨慎的方式完成:
@Configuration
class MybatisConfig {
@Bean(name=Array("persistenceContext"))
def persistenceContext(@Autowired dataSource: DataSource) = {
val config = org.mybatis.scala.config.Configuration(Environment("default", new JdbcTransactionFactory(), dataSource))
config.addSpace("item") { space =>
space ++= FooDao
space ++= BarDao
}
config.createPersistenceContext
}
}
没有ContextLoaderListener
,一切正常,但在添加后,它会因给定的异常而失败。已加载mybatis scala配置文件,但无法找到映射器。