场景:

应用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的更多相关文章

  1. 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 ...

  2. 多个@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 ' ...

  3. expected single matching bean but found 2

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'acc ...

  4. 深入Spring Boot:怎样排查expected single matching bean but found 2的异常

    写在前面 这个demo来说明怎么排查一个常见的spring expected single matching bean but found 2的异常. https://github.com/hengy ...

  5. spring依赖注入单元测试:expected single matching bean but found 2

    异常信息:org.springframework.beans.factory.UnsatisfiedDependencyException: Caused by: org.springframewor ...

  6. spring " expected single matching bean but found 2" 问题一例。

    初入java,使用spring时遇到一个问题,左边是一个接口和实现.右边是service和实现. @Service@Transactional(rollbackFor = Exception.clas ...

  7. 多数据源报错 expected single matching bean but found 2: xxx,xxx

    问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...

  8. Spring 3.2 @Autowired异常:expected single matching bean but found 2

    在使用Sping做单元测试时候,对RequestMappingHandlerAdapter(从处理器包装过来的适配器)进行自动装配, 发现报:expected single matching bean ...

  9. 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整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...

随机推荐

  1. MongoDB的基本查询

    .查询所有的电影名称以及评分 db.data2.find( {},{,} ) .获取所有评分大于等于9.0的电影名称,以及制作的国家 db.data2.find( {"subject.rat ...

  2. MongoError: Cannot update '__v' and '__v' at the same time,错误解决办法

    1.讲查询的结果,原封不动的插入到另一个表中,结果报错了:MongoError: Cannot update '__v' and '__v' at the same time,起初认为是mongodb ...

  3. (转)JavaWeb学习之Servlet(二)----Servlet的生命周期、继承结构、修改Servlet模板

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140466.html 一.http协议回顾: 在上一篇文章中:JavaW ...

  4. 如何绘制UML图?

    首先推荐在线绘制UML的网址:https://www.processon.com/,很好用. 在软件开发过程中,开发人员往往需要通过绘制类图来理清业务的实现思路,从而方便代码实现,也便于后期的代码维护 ...

  5. 3ds max学习笔记(五)--操作工具

    一些快捷:移动,旋转,缩放右键可调整数据或者直接右键点开也可以看到或者快捷键W,E,R 复制物体:摁住shift+移动工具,往想要复制的位置拖拽(实例方式复制)亦可选择多个父对象

  6. PHP03

    PHP03 1.提交地址: action.用户点击提交后,发送请求的地址.一般为了便于维护,最常见的是提交给当前文件,然后在当前文件判断是否为表单提交请求,表单的处理逻辑放在Html之前,为了避免写死 ...

  7. poj3253 Fence Repair(贪心+哈夫曼 经典)

    https://vjudge.net/problem/POJ-3253 很经典的题,运用哈夫曼思想,想想很有道理!! 具体实现还是有点绕人,最后被long long卡了一下,看数据大小的时候单纯相乘了 ...

  8. 1、mysql初识

    之前我们写代码需要存取信息时用的是文件可是用文件存取数据非常局限,今天我们将走进一个新的世界mysql 本片导航: 数据库由来 数据库概述 mysql介绍 下载安装 mysql软件基本管理 初识sql ...

  9. oracle操作字符串:拼接、替换、截取、查找、长度、判断

    1.拼接字符串 1)可以使用“||”来拼接字符串 select '拼接'||'字符串' as str from dual 2)通过concat()函数实现 select concat('拼接', '字 ...

  10. Css3实现波浪线效果1

    一.波浪线 ,常用 .info::before { content: ''; position: absolute; top: 30px; width: 100%; height: 0.25em; b ...