java - Injection of autowired dependencies failed with Qualifier -


i have tried options find anywhere, looked @ questions asked on topic , tried solutions given in those, nothing worked, error.

errors

info: loading xml bean definitions class path resource [spring.xml] exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'circle': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire method: public void spring.springdemo.circle.setcenter(spring.springdemo.point); nested exception org.springframework.beans.factory.nouniquebeandefinitionexception: no qualifying bean of type [spring.springdemo.point] defined: expected single matching bean found 3: pointa,pointb,pointc     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:292)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1185)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:537)     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:475)     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:304)     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:228)     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:300)     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:195)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:700)     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:760)     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:482)     @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139)     @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83)     @ spring.springdemo.drawingapp.main(drawingapp.java:10) caused by: org.springframework.beans.factory.beancreationexception: not autowire method: public void spring.springdemo.circle.setcenter(spring.springdemo.point); nested exception org.springframework.beans.factory.nouniquebeandefinitionexception: no qualifying bean of type [spring.springdemo.point] defined: expected single matching bean found 3: pointa,pointb,pointc     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredmethodelement.inject(autowiredannotationbeanpostprocessor.java:596)     @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:87)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:289)     ... 13 more caused by: org.springframework.beans.factory.nouniquebeandefinitionexception: no qualifying bean of type [spring.springdemo.point] defined: expected single matching bean found 3: pointa,pointb,pointc     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:967)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:855)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredmethodelement.inject(autowiredannotationbeanpostprocessor.java:553)     ... 15 more 

the files created in example below.

spring.xml schema defination

<?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"        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"> 

this place wants apply autowired.

 <bean id="circle" class="spring.springdemo.circle">  </bean>  <bean id="pointa" class="spring.springdemo.point">     <qualifier value="circlerelated"/>     <property name="x" value="0"/>     <property name="y" value="0"/> </bean> <bean id="pointb" class="spring.springdemo.point">         <property name="x" value="-20"/>         <property name="y" value="0"/>     </bean>     <bean id="pointc" class="spring.springdemo.point">         <property name="x" value="20"/>         <property name="y" value="0"/>     </bean> 

these classes those, have added.

    <bean class="org.springframework.beans.factory.annotation.qualifierannotationautowirecandidateresolver"/>     <bean class="org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor"/> 

circle.java class, thats object populated autowire

import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.qualifier;   public class circle implements shape{     private point center;      @override     public void draw() {         system.out.println("drawing circle");         system.out.println("point : ("+center.getx()+", "+center.gety()+")");     }     public point getcenter() {         return center;     }     @autowired     @qualifier("circlerelated")     public void setcenter(point center) {         this.center = center;     }  } 

i advice remove <qualifier value="circlerelated"/> xml , inject dependency straight forward id. id in xml enough in of cases, qualifier can used specific cases. , convention use lowercase first letter of id or qualifier.

so, change circlerelated of @qualifier("circlerelated") existing id @qualifier("pointa"), @qualifier("pointb") or @qualifier("pointc")


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -