今天使用基于MapperFactoryBean来实现MyBatis与Spring的整合,使用Mapper接口编程,一直报一个错误,调试了很久
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘customerMapper’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type ‘java.lang.String’ to required type ‘java.lang.Class’ for property ‘mapperInterface’; nested exception is java.lang.IllegalArgumentException: Cannot find class [mapper.CustomerMapper]
调试了很久,才发现是Mapper接口的名称和对应的Mapper.xml映射文件的名称不一致
在使用Mapper接口编程的方式,需要遵循一些规范