@Qualifier funktioniert nicht mit XML -basierter Konfiguration in Frühjahr 6.2Java

Java-Forum
Anonymous
 @Qualifier funktioniert nicht mit XML -basierter Konfiguration in Frühjahr 6.2

Post by Anonymous »

Ich lerne Bean-Konzepte mithilfe von XML -basierte Konfiguration, aber ich habe ein Problem mit der @Qualifier Annotation.
Hier ist meine Klasse: < /p>

Code: Select all

@Getter
@Setter
public class CircleWithAnnotation implements Shape {

@Autowired
//    @Qualifier("circleRelated")
@Qualifier("zeroCenter") // This also refers to the same bean as "circleRelated"
private Point center;

@Resource(name = "zeroCenter")
private Point centerX; // This refers to the same bean as "zeroCenter" field above

public void draw() {
System.out.println("Circle drawn: \n"
+ "center = (" + center.getX() + ", " + center.getY() + ")\n"
);
System.out.println("Circle with centerX drawn: \n"
+ "centerX = (" + centerX.getX() + ", " + centerX.getY() + ")\n"
);
}
}

public class DrawingApp {

public static void main(String[] args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
context.registerShutdownHook();
CircleWithAnnotation circleWithAnnotation = (CircleWithAnnotation) context.getBean("circleWithAnnotation");
circleWithAnnotation.draw();
}
Wenn ich die Hauptmethode oben ausführe, erhalte ich den folgenden Fehler:

Code: Select all

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'circleWithAnnotation': Unsatisfied dependency expressed through field 'center': No qualifying bean of type 'in.abc.xyz.practice.javabrains.spring.shapes.Point' available: expected single matching bean but found 7: zeroPoint,point2,point3,pointA,pointB,pointC,zeroCenter
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'circleWithAnnotation': Unsatisfied dependency expressed through field 'center': No qualifying bean of type 'in.abc.xyz.practice.javabrains.spring.shapes.Point' available: expected single matching bean but found 7: zeroPoint,point2,point3,pointA,pointB,pointC,zeroCenter
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:788)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:768)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:146)
meine vollständigen Beans.xml Datei

Code: Select all





























 



























































































































Hinweis:

Keine der @Qualifier s über funktioniert, aber die @resource Annotation funktioniert! XML Datei (wie in vielen anderen Antworten hier auf Stack-Overflow angegeben), aber ohne Erfolg. In diesem Fall erhalte ich den folgenden Fehler: < /li>
< /ol>

Code: Select all

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'circleWithAnnotation': Unsatisfied dependency expressed through field 'center': No qualifying bean of type 'in.abc.xyz.practice.javabrains.spring.shapes.Point' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier("zeroCenter")}
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'circleWithAnnotation': Unsatisfied dependency expressed through field 'center': No qualifying bean of type 'in.abc.xyz.practice.javabrains.spring.shapes.Point' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier("zeroCenter")}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:788)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:768)
Ich bin ziemlich neu im Frühling - also würde jede Hilfe geschätzt.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post