org.springframework.beans.factory.BeanCreationException一例解决方案


环境:

maven+spring+mybatis

问题:在Junit下面可以正常调用到service,操作数据库;在正式的main方法里面却出现

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘service-xxx-service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xxx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}

结果:发现在main方法里面调用spring的配置文件时,直接指定了spring-app.xml,而数据库配置在另外的xml中,无法读取到该配置,所以报错,修改为junit代码里面的spring-*.xml即可。

版权声明:本文《org.springframework.beans.factory.BeanCreationException一例解决方案》为【屁民部落】原创/翻译文章,转载时请注明出处!
本文地址:http://pimin.net/archives/514

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">