场景:

应用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. Mysql中大数据类型的存取

    标准SQL中提供了八种大数据类型 上面四种是针对字节数据(二进制字符串类型,主要存储图片.音频信息等),下面四种是针对字符数据(非二进制字符串类型,纯文本文件). MySql中不使用标准SQL中针对字 ...

  2. Java 状态模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述状态(State)模式的:状态模式,又称状态对象模式(Pattern of Objects for States),状态模式是对象的行为模 ...

  3. uploadify Cookie 验证登入上传问题

    上传文件时必须验证是否已登入. 当用FormsAuthentication做登入,使用FormsAuthentication.FormsCookieName进行验证是否已登入即可. <scrip ...

  4. Multiple Tasks Z

    public static async Task executeParallel<T>(this IEnumerable<T> items, int limit, Func&l ...

  5. 为Ubuntu新创建用户创建默认.bashrc并自动加载

    首先,su – 到新创建的用户 拷贝默认的.bashrc过来   1 cp /etc/skel/.bashrc ~/ 然后创建.profile文件   1 vi ~/.profile 粘贴下面的内容 ...

  6. 对类的理解(c++)

    介绍目录: 1.类成员 1.1 成员函数 1.2 构造函数 1.2.1 对构造函数的理解 1.2.2成员初始化列表 1.2.3必须使用成员初始化列表的几种情况 1.2.4对于拷贝构造函数的参数是一个引 ...

  7. Git上传空文件夹

    git上传的文件夹为空的时候 1,先删除空的文件夹 参考:https://www.cnblogs.com/wang715100018066/p/9694532.html 2,这个只能说是技巧不能说是方 ...

  8. from __future__ import print_function的作用

    阅读代码的时候会看到下面语句: from __future__ import print_function 该语句是python2的概念,那么python3对于python2就是future了,也就是 ...

  9. ionic android升级检查

    https://www.cnblogs.com/zxj159/p/4421578.html 坑: 放到cordova.file.DataDirectory下载异常? 只好cordova.file.ex ...

  10. A Sample Linker Script

    from:http://www.hertaville.com/a-sample-linker-script.html A sample script file that will work with ...