mybatis 搭建项目后报错,required a single bean, but 2 were found

Description:

Field sysUserService in com.sharlock.blog.controller.SysUserController required a single bean, but 2 were found:
    - sysUserServiceImpl: defined in file [C:\Users\sharlock\IdeaProjects\easycloud\target\classes\com\sharlock\blog\service\impl\SysUserServiceImpl.class]
    - ISysUserService: defined in file [C:\Users\sharlock\IdeaProjects\easycloud\target\classes\com\sharlock\blog\service\ISysUserService.class]


Action:

很奇怪,为什么容器里会出现两个 bean 呢?最奇怪的是第二个 bean 还不是驼峰命名的。

后来想来想去应该是 @MapperScan 的扫包范围需要细化,这个注解会扫描对应路径下的所有接口。

package com.sharlock;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.sharlock.**") //错误写法,太宽泛
@MapperScan("com.sharlock.**.dao") //正确写法
public class StartApplication {

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

}

转载请注明来源。 欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。 可以在下面评论区评论,也可以邮件至 sharlot2050@foxmail.com。

文章标题:mybatis 搭建项目后报错,required a single bean, but 2 were found

字数:183

本文作者:夏来风

发布时间:2021-04-04, 20:00:24

原始链接:http://www.demo1024.com/blog/mybatis-error-required-a-single-bean-but-2-were-found/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。