-1

I've got a class that extends a collection, specifically a HashMap. I'd like to use it as an autowired field in another class, however when I try to use the @autowired or @resource annotations in the following way:

@Autowired
private myCollectionClass<String, Object> myCollectionClass;

I get the error: no qualifying bean of type [my collection class]

How can I autowire the class?

(I cannot use xml in the project)

Zerg
  • 739
  • 4
  • 11
  • 22

2 Answers2

1

The simplest solution is to use @Resource specifying the bean id

@Resource(name="myCollection")
private MyCollectionClass<String, Object> myCollectionClass;

Or you could use @Qualifier in conjunction with @Autowired

@Autowired @Qualifier("myCollection")
private MyCollectionClass<String, Object> myCollectionClass;
lance-java
  • 25,497
  • 4
  • 59
  • 101
0

have you annotated myCollectionClass?

If not, You need to annotate myCollectionClass as well with @Component for spring container to qualify the object based on class name or class type.

You can also use @Qualifier and specify the qualifier class name.

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
  • I had annotated the collection class as a component before autowiring it in another class, but its still the same error – Zerg Sep 26 '16 at 08:14