Spring无法自动连接依赖项

ruarlubt  于 2024-01-05  发布在  Spring
关注(0)|答案(1)|浏览(154)

我有一个应用程序,这不是一个动态的Web项目。我有这样的安排,它像一个通过接口暴露的jar形式的库。我试图自动连接到我的API项目,这是动态的Web项目这个接口。但它抛出bean创建异常
1.我在库中有一个MyLibraryCofiguration类,它有@Configuration和@Import以及@ PencentScan。

  1. @Configuration
  2. @Import({ BasicConfiguration.class, OperationalLoggingConfiguration.class, RestConfiguration.class })
  3. @ComponentScan("nl.ming.cram")
  4. public class MyConfiguration() {
  5. public MyConfiguration() {
  6. packages("nl.ming.cram.gateway");
  7. }
  8. @Bean
  9. public MyInterface getMyInterface() {
  10. return new MyImpl();
  11. }
  12. }

字符串
1.我的API项目有MyApiCofiguration类,它有@Import,我在其中导入我的MyLibraryCofiguration类。在同一个类中,我使用了:

  1. @Configuration
  2. @Import({
  3. MyConfiguration.class
  4. })
  5. @ComponentScan({"nl.ming.api.creditcardlist"})
  6. public class CreditCardListConfiguration {
  7. @Bean
  8. public MyInterface getMyInterface() {
  9. return new CramImpl();
  10. }
  11. }


1.在我的API项目中,在MyApiService类中-我有@Autowired MyInterface来访问库jar的方法,如下所示:

  1. @Component
  2. public class MyAPIService {
  3. @Autowired
  4. MyInterface MyInterface;
  5. }


它为getMyInterface抛出Bean创建异常,如下所示:
org.springframework.beans.factory.BeanCreationException:
创建名为“creditCardService”的bean时出错:自动连接依赖项的注入失败;
嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动连接字段:nl.ing.cram.gateway.CramInterfacenl.ing.api.creditcardlist.services.CreditCardService.cramIface;
嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'getCramInterface'的bean时出错:自动连接依赖项的注入失败;
嵌套异常是org.springframework.beans.factory.BeanCreationException:Could not autowire field:private nl.ing.cram.dao.CramDaonl.ing.cram.gateway.CramImpl.cramDao;
嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'cramDao'的bean时出错:注入资源依赖失败;
nested exception is org.springframework.beans.factory. NoSuchBeanOperationException:未找到依赖项的[nl.ing.sc.customerrequest.configurecustomerrequest1.configureCustomerRequestServiceOperationClient]类型的合格bean:应至少有1个bean符合此依赖项的自动连接候选项。依赖项注解:{@javax.annotation.Resource(shareable=true,mappedName=,description=,name=,type=class java.lang.Object,lookup=,authenticationType=CONTAINER)}

nwo49xxi

nwo49xxi1#

Spring不能用于任何Java应用程序。

  1. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type

字符串
我可以看到上面的异常,这意味着spring可以找到你注入的类型,但不能找到它的实现。
检查你的spring-config:-

  1. <context:component-scan base-package="..." />


异常堆栈跟踪中的异常原因:-
在您的nl.ing.cram.gateway.CramImpl.cramDao类中,由于无法找到其实现,因此无法注入类型为CustomerRequestServiceOperationClient的依赖项。

相关问题