java - Dependency injection failed when two different packages are interlinked in spring -
i not able autowire when field exists in different package autowired.
my code looks this
injecting class
package com.vmware.vchs.networkservice.extensions.http @component public class httpserviceclient implements contextaware { @autowired jmxagent jmxagent; .... };
injected class
package com.vmware.vchs.networkservice.monitoring; @component public class jmxagent { };
my component scan xml file looks this
<?xml version="1.0" encoding="utf-8"?> <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" xmlns:bean="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" <context:property-placeholder location="classpath:environment.properties" ignore-unresolvable="false"/> <bean:component-scan base-package="com.vmware.vchs.networkservice"/> </beans>
the error
exception in thread "main" org.springframework.beans.factory.beancreationexception: err or creating bean name 'httpserviceclient': injection of autowired dependencies fai led; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: com.vmware.vchs.networkservice.monitoring.jmxagent com.vmware.vchs. networkservice.extensions.http.httpserviceclient.jmxagent; nested exception org.spri ngframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [co m.vmware.vchs.networkservice.monitoring.jmxagent] found dependency: expected @ lea st 1 bean qualifies autowire candidate dependency. dependency annotat ions: {@org.springframework.beans.factory.annotation.autowired(required=true)}
in order automatically detecting classes , registering bean definitions use context
not bean
:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="org.example"/> </beans>
update
<context:component-scan base-package="com.vmware.vchs.networkservice"/> <context:component-scan base-package="com.vmware.vchs.networkservice.extensions.http"/>
Comments
Post a Comment