Note that there are some explanatory texts on larger screens.

plurals
  1. POElement is not allowed here: for qualifier in spring bean definition in IntelliJ
    primarykey
    data
    text
    <p>This is the file, I am trying examples from: <a href="http://simplespringtutorial.com/annotations.html" rel="nofollow">http://simplespringtutorial.com/annotations.html</a></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;context:annotation-config /&gt; &lt;bean id="foo" class="annotation.Foo"&gt; &lt;property name="name" value="Daniel"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="anotherFoo" class="annotation.Foo"&gt; &lt;qualifier value="secondaryFoo"&gt;&lt;/qualifier&gt; &lt;property name="name" value="Shirley"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="bar" class="annotation.Bar" /&gt; &lt;/beans&gt; </code></pre> <p>This is the Bar class import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;</p> <pre><code>public class Bar { @Autowired @Qualifier(value="anotherFoo") private Foo foo; @Resource(name="foo") private Foo foo2; public void setFoo(Foo foo) { this.foo = foo; } public void printFooName(){ System.out.println(foo.getName()); // System.out.println(foo2.getName()); } } </code></pre> <p>This is the test bar which loads the xml file</p> <pre><code>import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestFooBar { public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "test2.xml"); Bar bar = applicationContext.getBean("bar", Bar.class); bar.printFooName(); System.out.println(bar.toString()); /* * if a single definition of a class type exists, then u can get the * instance by this way also. No need to specify Id */ Foo foo = applicationContext.getBean(Foo.class); System.out.println(foo.getName()); } } </code></pre> <p>When I ran the application, the following is the stack trace:</p> <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bar': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private annotation.Foo annotation.Bar.foo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [annotation.Foo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=anotherFoo)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83) at annotation.TestFooBar.main(TestFooBar.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private annotation.Foo annotation.Bar.foo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [annotation.Foo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=anotherFoo)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282) ... 18 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [annotation.Foo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=anotherFoo)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474) ... 20 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload