Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

@Autowired does not inject a Map ?

 
Ranch Hand
Posts: 1871
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, in Getting Started with Spring Framework 4th edition , in section 6-6 JSR 250's @Resource annotation, there is a quote:


@Autowired annotation doesn't work for beans that are themselves of collection or Map type. For instance, if you define a bean using util schema's map element, you can't autowire it using @Autowired annotation.


But as I tried , it works with @Autowired.




To my surprised, the output works fine. It should not work with @Autowired.


INFO  sample.spring.SampleApp - retrieving from my map : Maryland

 
Rancher
Posts: 527
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you are using a new version and they changed it?  Or maybe it's because you extended HashMap? It might be talking about if your bean was a Map<> as opposed to like HashMap. No idea either way
 
Saloon Keeper
Posts: 21960
149
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"collection or Map type"?  

A Map is a collection! Someone doesn't seem to know what they are talking about.

And this doesn't jibe with my experience with Spring in general. I think at best it's related to a particular environment. I note that your Map is a @Component and not literally a @Resource.
 
Himai Minh
Ranch Hand
Posts: 1871
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the quote:


@Autowired annotation doesn't work for beans that are themselves of collection or Map type. For instance, if you define a bean using util schema's map element, you can't autowire it using @Autowired annotation.



It refers to a bean that is a Map.  So, @Component MyMap is a bean and a Map type.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic