MyBatisPlus:No qualifying bean BaseMapper available: expected single matching bean but found 2

原文链接:https://www.cnblogs.com/icebutterfly/p/9851853.html

场景:

应用MyBatis Plus 和通用Mapper

继承自ServiceImpl实现对Service里的方法进行包装再处理。

public interface IServiceBase2 {
}
public class ServiceBaseImpl2,P extends Model

,D extends AbstractDTO> extends ServiceImpl implements IServiceBase2 { private Class

poClazz; private Class 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

) types[1]; } if (types[2] instanceof Class) { dtoClazz = (Class) 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,P extends Model

,D extends AbstractDTO> extends ServiceImpl implements IServiceBase2 { }

 

你可能感兴趣的:(springboot)