In the following example, the annotation @Qualifierdoes not work. I declare the properties file in the Spring XML configuration as follows:
<context:property-placeholder />
<util:properties id="xx" location="classpath:file.properties" />
The util.properties file is then automatically added to the @Componentannotated class :
@Autowired
private Properties props;
The following exception is thrown:
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type [java.util.Properties] is defined: expected single matching
bean but found 2: xx,systemProperties
So there are two properties files, one of which is xx . But when I add the annotation @Qualifier...
@Autowired
@Qualifier("xx")
private Properties props;
... this exception is thrown:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [java.util.Properties] 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=xx)}
Without @QualifierSpring, two instances of java.util.Properties were found, one of which was xx . But with @Qualifierhe does not see the xx file . The same problem occurs when used @Resource.
What is configured incorrectly? Thanks