wood burning stoves*
The moose likes Spring and the fly likes Java config: could not autowired a List. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Java config: could not autowired a List." Watch "Java config: could not autowired a List." New topic
Author

Java config: could not autowired a List.

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
With code 1: using Java config.

The autowired is working for restTemplate.
The autowired is NOT working for thirdpartyServices

The log show ThirdpartyServiceConfiguration constructor get called.
The log show getRestTemplate get called.
The log did not show getThirdpartyServices get called.

What do I miss?

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1676
    
    7

@Autowired works differently for collections. It would work if for example you did this



In this case your List would contain 2 beans of type ThirdParty service one with a name instance1 and one instance2. Basically what it does is scan the context for dependencies of that type and adds them to the collection.

If you want to do what you are doing you should use the @Resource annotation on your list.


[How To Ask Questions][Read before you PM me]
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4


Thanks for your @ResourceFullness. It worked. (Should we create this new tag?)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java config: could not autowired a List.