首先是在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管理,或者没有扫描。