我有一个应用程序,这不是一个动态的Web项目。我有这样的安排,它像一个通过接口暴露的jar形式的库。我试图自动连接到我的API项目,这是动态的Web项目这个接口。但它抛出bean创建异常
1.我在库中有一个MyLibraryCofiguration类,它有@Configuration和@Import以及@ PencentScan。
@Configuration
@Import({ BasicConfiguration.class, OperationalLoggingConfiguration.class, RestConfiguration.class })
@ComponentScan("nl.ming.cram")
public class MyConfiguration() {
public MyConfiguration() {
packages("nl.ming.cram.gateway");
}
@Bean
public MyInterface getMyInterface() {
return new MyImpl();
}
}
字符串
1.我的API项目有MyApiCofiguration类,它有@Import,我在其中导入我的MyLibraryCofiguration类。在同一个类中,我使用了:
@Configuration
@Import({
MyConfiguration.class
})
@ComponentScan({"nl.ming.api.creditcardlist"})
public class CreditCardListConfiguration {
@Bean
public MyInterface getMyInterface() {
return new CramImpl();
}
}
型
1.在我的API项目中,在MyApiService类中-我有@Autowired MyInterface来访问库jar的方法,如下所示:
@Component
public class MyAPIService {
@Autowired
MyInterface MyInterface;
}
型
它为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)}
1条答案
按热度按时间nwo49xxi1#
Spring不能用于任何Java应用程序。
字符串
我可以看到上面的异常,这意味着spring可以找到你注入的类型,但不能找到它的实现。
检查你的spring-config:-
型
异常堆栈跟踪中的异常原因:-
在您的nl.ing.cram.gateway.CramImpl.cramDao类中,由于无法找到其实现,因此无法注入类型为CustomerRequestServiceOperationClient的依赖项。