本人完整报错信息:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\study\school_delivery\target\classes\com\shelbourne\schooldelivery\mapper\UserMapper.class]: Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\study\school_delivery\target\classes\mapper\User.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.shelbourne.schooldelivery.mapper.UserMapper.selectPage. please check com/shelbourne/schooldelivery/mapper/UserMapper.java (best guess) and com/shelbourne/schooldelivery/mapper/UserMapper.java (best guess)
原因分析:mapper层同一个namespace中的方法重载导致,如下图写了两个selectPage
结论&解决方案:Mybatis的Mapper接口方法不能重载!在不同namespace中可以有方法名一样的接口,但是同一个namespace中的方法名不能重复,在这里删掉一个或者将其中一个selectPage改名即可。