spring - multi-module bean injection failure -
i have 2 maven modules, api , impl. impl di based , has next code
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> <context:component-scan base-package="com.name.mongo.client.impl" annotation-config="true"/> </beans>
note: used annotation-config repositoryimpl class has @repository annotation
i have 3rd sample maven module spring-jersey based , has api , impl dependencies. spring-jersey webapp working fine tested sample classes. here class modified class accessing service
@component @path("/payment") public class paymentservice { @autowired @qualifier(value="mongorepositoryimpl") mongorepository mongorepositoryimpl;
but when test project modules autowiring fails , see exception
org.springframework.beans.factory.beancreationexception: error creating bean name 'paymentservice': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: com.name.mongo.client.api.mongorepository com.mkyong.rest.paymentservice.transactionbo; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.name.mongo.client.api.mongorepository] found dependency: expected @ to the lowest degree 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true), @org.springframework.beans.factory.annotation.qualifier(value=mongorepositoryimpl)} @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:326) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1204) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:538) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:302) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:229) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:298) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:725) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4760) @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5184) @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150) @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:724) @ org.apache.catalina.core.containerbase.addchild(containerbase.java:700) @ org.apache.catalina.core.standardhost.addchild(standardhost.java:714) @ org.apache.catalina.startup.hostconfig.deploywar(hostconfig.java:919) @ org.apache.catalina.startup.hostconfig$deploywar.run(hostconfig.java:1704) @ java.util.concurrent.executors$runnableadapter.call(executors.java:511) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745) caused by: org.springframework.beans.factory.beancreationexception: not autowire field: com.name.mongo.client.api.mongorepository com.mkyong.rest.paymentservice.transactionbo; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.name.mongo.client.api.mongorepository] found dependency: expected @ to the lowest degree 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true), @org.springframework.beans.factory.annotation.qualifier(value=mongorepositoryimpl)} @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:542) @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:323) ... 26 more caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.name.mongo.client.api.mongorepository] found dependency: expected @ to the lowest degree 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true), @org.springframework.beans.factory.annotation.qualifier(value=mongorepositoryimpl)} @ org.springframework.beans.factory.support.defaultlistablebeanfactory.raisenosuchbeandefinitionexception(defaultlistablebeanfactory.java:1261) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1009) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:904) @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:514) ... 28 more
the issue impl module using spring bean instantiation consuming or api module i.e. spring-jersey webapp or api not aware of context existing. how can create them aware of contexts , interact each other.
spring spring-bean
No comments:
Post a Comment