zoukankan      html  css  js  c++  java
  • 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> {
    }
  • 相关阅读:
    hdu 4027 Can you answer these queries?
    Codeforces: Empty Triangle
    hdu 3006 The Number of set
    hdu 3645 Code Management System
    进度条作控件代码
    NORMAL
    callback
    三种形状匹配脚本
    移动点动画
    脚本管理
  • 原文地址:https://www.cnblogs.com/icebutterfly/p/9851853.html
Copyright © 2011-2022 走看看