springboot 报错解决org.springframework.beans.factory.BeanCreationException: Error creating bean with nam

新建springboot项目,后端使用了mybatisplus代码生成器。

使用测试类测mapper层时没有问题,测service就一直报错,报错内容如下。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lantu.xadmin.XAdminApplicationTests': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lantu.sys.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lantu.sys.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

在网上查,也问过chathpt。都说是注解没加,但是我明明都加了。

这是我的实现类注解

 启动类注解

测试类注解

 搞到最后发现是文件目录问题。

启动类必须和sys在同级目录。之前是建了一个和sys同级的包,把启动类放在那个包下面了。

问题解决,启动成功。

猜你喜欢

转载自blog.csdn.net/lina_lee1/article/details/130316101