required a bean of type 'com.xxx.xxx' that could not be found.错误

在编写MyBatis-Spring-Boot-Starter示例代码的时候遇到一个奇怪的问题,写了一个Mapper在Controller中使用@Autowire自动装载,却一直提示报错,找不到Mapper这个bean,错误信息如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-26 10:10:19.414 ERROR 17337 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field userMapper in com.reeson.learn.demo.controller.UserController required a bean of type 'com.reeson.learn.demo.mapper.UserMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.reeson.learn.demo.mapper.UserMapper' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:57324', transport: 'socket'

Process finished with exit code 1

google之后找到答案

@SpringBootApplication(scanBasePackages={
        "com.reeson.learn.demo.mapper"})

添加scanBasePackages之后问题解决。
stackoverflow问题

发布了11 篇原创文章 · 获赞 0 · 访问量 264
展开阅读全文

spring boot注入jar包中的接口总是提示that could not be found

06-12

首先是在spring boot项目中注入的jar包中的接口 ``` @Controller public class MessageTransferStationController { @Autowired private MessageClient messageClient; } ``` 其次,jar包中的MessageClient的源码 ``` public interface MessageClient { } ``` MessageClient分别有三个实现类 ``` public class CoreMessageClient implements MessageClient {} @Component public class SpringMessageClientImpl extends CoreMessageClient implements MessageClient {} public class Spring2MessageClientImpl extends CoreMessageClient implements MessageClient {} ``` 当我在spring boot项目中注入MessageClient接口的时候,启动报错: 017-06-12 15:06:53.281 WARN 9780 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'messageTransferStationController': Unsatisfied dependency expressed through field 'messageClient'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sinosoft.messageclient.MessageClient' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2017-06-12 15:06:53.283 INFO 9780 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat 2017-06-12 15:06:53.316 INFO 9780 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-06-12 15:06:53.431 ERROR 9780 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field messageClient in com.sinosoft.oa.message_transfer_station.web.MessageTransferStationController required a bean of type 'com.sinosoft.messageclient.MessageClient' that could not be found. Action: Consider defining a bean of type 'com.sinosoft.messageclient.MessageClient' in your configuration. Process finished with exit code 1 --- 请问各位大佬,为什么MessageClient为什么不能注入,我猜想过MessageClient的实现类没有被Spring管理,我看了jar包中源码有一个实现类加上了@Component注解 求教各位大佬,这是什么原因引起的? 注:引用jar包中的其它接口也测试过了,同样的错误,也就是说引用的这个jar包中的所有接口都没有被spring管理,或者没有扫描。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览