Skip to content

Autowiring inconsistency: @Qualifier works with HashMap but not with Map [SPR-17197] #21731

Closed
@spring-projects-issues

Description

@spring-projects-issues

Manfred Quasten opened SPR-17197 and commented

bean definition:

<bean id="instances" class="java.util.HashMap" >
 <constructor-arg>
 <map key-type="java.lang.String" value-type="java.lang.String">
 <entry key="0001" value="Beschreibung " />
...
 </map>
 </constructor-arg>
</bean>
public InstanceRepositoryImpl {

@Autowired
 InstanceRepositoryImpl(@Qualifier("instances") final Map<String,String> instances ) {
 this.instances= instances;
 }

}

 

Error Message:

No qualifying bean of type 'java.util.Map<java.lang.String, java.lang.String>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=instances)}

When I change Map to HashMap<String,String> it works: no exception is thrown.

It should work using the Map interface. The  @Qualifier annotation specifies the name; the bean exists.


Affects: 5.0.3

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions