十二月 03, 2019 7:04:50 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.binding.BindingException: Type interface mapper.UserQueryMapper is already known to the MapperRegistry.
我这里引起的原因是:
<mappers>
<!--通过resource方法一次加载一个映射文件-->
<mapper resource="sqlmap/UserMapper.xml"></mapper>
<mapper resource="sqlmap/UserQueryMapper.xml"></mapper>
<!--批量加载Mapper-->
<package name="mapper"/>
</mappers>
处理方法是:
<mappers>
<!--通过resource方法一次加载一个映射文件-->
<mapper resource="sqlmap/UserMapper.xml"></mapper>
<mapper resource="sqlmap/UserQueryMapper.xml"></mapper>
<!--批量加载Mapper-->
否则mappe文件会重复使用相关接口造成错误。
本文详细解析了在使用MyBatis框架时遇到的重复接口注册错误,并提供了具体的解决方案。错误源于同时使用资源方法加载映射文件和批量加载Mapper,导致UserQueryMapper接口重复注册。文章指导如何正确配置,避免此问题。
953

被折叠的 条评论
为什么被折叠?



