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整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
随机推荐
- 南方IT学校期末PCB结课项目考试(实操)说明书
南方IT学校期末结课项目考试(实操)说明书(一) 课程:<印制电路板设计技术>(二) 项目:笔记本电脑电源适配器的印制电路板设计(三) 背景说明:如今笔记本已经进入千家万户,作为给电脑充电 ...
- 统一各浏览器CSS 样式——CSS Reset
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, ...
- Js全等和等于
Javascript只有六个假值(用在条件if的判断) 全等于 类型不同,返回false类型相同,则 等于 类型相同:同上=== 类型不同:尝试类型转换==[不是真值和假值的比较] null == u ...
- win7生成ssh key配置到gitlab
测试服务上使用ip访问gitlab,比如http://192.168.0.2/,创建用户并登陆后创建一个项目,比如git@gitlab.demo.com:demo/helloworld.git 如果想 ...
- C#扩展方法实现
C#提供了一种机制,可以扩展系统或者第三方类库中的方法.比如说想在string类型的对象里面多一个ToInt32(),来方便的将字符转换成整形.在实现的过程中的关键字为static和this即可. ...
- linux下下载redis,并且编译
1:下载.解压.编译$ wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ tar xzf redis-3.0.6.tar.gz $ ...
- instanceof详解
instanceof 用于确定一个 PHP 变量是否属于某一类 class 的实例: <?php class MyClass { } class NotMyClass { } $a = new ...
- 如何给webbrowser指定IE版本
void Button1Click(object sender, EventArgs e) { RegistryKey rk = Registry.LocalMachine; ...
- socket.io常用api
1. 服务端 io.on('connection',function(socket)); 监听客户端连接,回调函数会传递本次连接的socket io.sockets.emit('String',dat ...
- SpringCloud无废话入门03:Feign声明式服务调用
1.Feign概述 在上一篇的HelloService这个类中,我们有这样一行代码: return restTemplate.getForObject("http://hello-servi ...