MyBatis Plus:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4
场景:
应用MyBatis Plus 和通用Mapper
继承自ServiceImpl实现对Service里的方法进行包装再处理。
public interface IServiceBase2<T extends AbstractDTO> {
}
public class ServiceBaseImpl2<M extends BaseMapper<P>,P extends Model<P>,D extends AbstractDTO> extends ServiceImpl<M,P> implements IServiceBase2<D> {
private Class<P> poClazz;
private Class<D> dtoClazz;
public ServiceBaseImpl2(){
Type superClass = getClass().getGenericSuperclass();
if (superClass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) superClass;
Type[] types = parameterizedType.getActualTypeArguments();
if (types != null && types.length == 3) {
if (types[1] instanceof Class) {
poClazz = (Class<P>) types[1];
}
if (types[2] instanceof Class) {
dtoClazz = (Class<D>) types[2];
}
}
}
}
@Override
public D selectByIdDTO(Serializable var1) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
P p = super.selectById(var1);
String classPath = poClazz.getName() + "POJOMapperImpl";// "com.api.modular.clinicalcase.dto.mapper.ClinicalcasePOJOMapperImpl";
classPath = classPath.replace("model","dto.mapper");
Class mapperClazz = Class.forName(classPath);
Object newInstance = mapperClazz.newInstance();
Method[] methods = mapperClazz.getMethods();
Method method = mapperClazz.getMethod("doToDto", poClazz);
D result = (D) method.invoke(newInstance, p);
return result;
}
}
错误:
启动项目报错:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4
解决:
将ServiceBaseImpl 更改为抽象类
public abstract class ServiceBaseImpl2<M extends BaseMapper<P>,P extends Model<P>,D extends AbstractDTO> extends ServiceImpl<M,P> implements IServiceBase2<D> {
}
MyBatis Plus:No qualifying bean of type 'com.baomidou.mybatisplus.mapper.BaseMapper<?>' available: expected single matching bean but found 4的更多相关文章
- Spring Boot 自定义配置文件异常"expected single matching bean but found 2"
运行环境:Spring Boot 2.5.0, IDEA 2020.3.2 异常详细信息: Injection of resource dependencies failed; nested exce ...
- 多个@bean无法通过@resource注入对应的bean(org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found )
一.异常 org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ' ...
- expected single matching bean but found 2
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...
- 深入Spring Boot:怎样排查expected single matching bean but found 2的异常
写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...
- spring依赖注入单元测试:expected single matching bean but found 2
异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException: Caused by: org.springframewor ...
- spring " expected single matching bean but found 2" 问题一例。
初入java,使用spring时遇到一个问题,左边是一个接口和实现.右边是service和实现. @Service@Transactional(rollbackFor = Exception.clas ...
- 多数据源报错 expected single matching bean but found 2: xxx,xxx
问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...
- Spring 3.2 @Autowired异常:expected single matching bean but found 2
在使用Sping做单元测试时候,对RequestMappingHandlerAdapter(从处理器包装过来的适配器)进行自动装配, 发现报:expected single matching bean ...
- NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate
在搭建SSM spring springmvc mybatis整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
随机推荐
- 潭州课堂25班:Ph201805201 django 项目 第四课 项目搭建 课堂笔记)
创建一用户,授予对这个 myblog 库的所有表的权限(.*),在任何 ip 地址中访问(@“%”), 刷新: 退出,用新创建的用户登录,并进入这个库, 在昨天创建的项目中,配置文件中 为了数据库的案 ...
- System.out.println()和System.err.println()
在一次笔试中遇到了一个System.err.println()的输出,之前没有见过,回来查一查,自己还是见识太短,来补充一下. 首先看一看jdk中 来一个简单的实验 第一次显示 第二次显示 1. 发现 ...
- HTML(一)
html基本结构 一个html的基本结构如下: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- LinkedList源码分析和实例应用
1. LinkedList介绍 LinkedList是继承于AbstractSequentialList抽象类,它也可以被当作堆栈.队列或者双端队列使用. LinkedList实现了Deque接口,即 ...
- button标题左对齐
Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//左对齐(UIControlContentHo ...
- JS_高程6.面向对象的程序设计(2)创建对象_3 构造函数存在的问题
# 上次讲到用构造函数的模式来创建对象,相对于工厂模式,解决可对象识别的问题. function Person(name,age,job){ this.name=name; this.age=age; ...
- pygame-KidsCanCode系列jumpy-part13-改进跳跃
这节研究下跳跃如何做得更自然,先看看之前的跳跃有什么问题,我们把settings.py里的初始化参数调整下: # starting platform # PLATFORM_LIST = [(5, HE ...
- github远程建了分支,本地看不到的问题
原因:Git branch -a 查看的是本地仓库的所有分支 远程新建的没有同步前 就是看不到 解决:$git checkout master //首先切到master分支 $git pull ...
- 微信小程序+微信管理后台+微信用户前台
代码地址如下:http://www.demodashi.com/demo/15043.html #### 微信小程序+微信管理后台+微信用户前台 #### 产品介绍 基础功能开发:景区微信地图导游.天 ...
- shell脚本启动语法错误syntax error near unexpected token '{
执行shell脚本时失败,报语法错误,但脚本内容检查正常 原因为该脚本是在非Linux系统下编辑之后放到系统执行的,文件模式类型非Linux系统匹配的模式类型. 查看文件的模式类型 显示文件的模式类型 ...