mybatis mapper 名字重复报错解决方法:使用@Repository并指定值

mybatis扫描不同包下可能存在两个同名Mapper导致spring报错

org.springframework.context.annotation.ConflictingBeanDefinitionException: 
Annotation-specified bean name 'testMapper' for bean class [org.freeone.springboot.multi.datasource.dao.school02.TestMapper] conflicts with existing, non-compatible bean definition of same name and class [org.mybatis.spring.mapper.MapperFactoryBean]

解决方法

在其中一个mapper上添加注解@Repository并指定值,例如

@Repository("school01TestMapper")
public interface TestMapper {

    @Select("SELECT now() from dual ")
    String now();

    @Select("SELECT DATABASE() from dual ")
    String currentDatabase();
}
posted @ 2022-07-11 10:55  闲一话  阅读(2519)  评论(0编辑  收藏  举报