File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container

 
hisham ragheb
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,


i created a Person bean which has a private field named degrees of type Map<String,Degree> and annotated it with @Autowired
i have also 2 classes who are different implementations of the Degree class, i defined and initialized them in the beans.xml

the problem arise when i try to get this field using its getter method where i always gets null. This mean this Map<String,Degree> is not initialized with the target beans

why is that?


regards

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Application Frameworks forum.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without any code or configuration I don't see how anybody could help.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Spring.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have a Map bean specified.
 
hisham ragheb
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:You should have a Map bean specified.


The problem that @Autowire somtimes works and most time it dont when its used with collections(List,Set Map)..the container dont create the collection and inject the beans by type in it

this is my problem...the collection returned sometimes is null other times contains the injected beans

I dont know why
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your configuration.
 
hisham ragheb
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:Please post your configuration.


ok..but becareful that naming may not make so much sense here


A Person class:




A Career Abstract class:




(Subclass of Career) MSC class:




The beans.xml





The Main class (for testing):




also, thank you for your concern
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no Map bean. You need a Map bean.
 
hisham ragheb
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:There is no Map bean. You need a Map bean.


I'm trying similar example as the one in (Apress Spring Recipes) book, but he didn't define Map bean in this example?

can you show me how can i do it
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
hisham ragheb
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Freddy Wong wrote:


im using spring 2.5.5

so i tried to use this which didnt work



i tried this also which didnt work




i still always get NullPointerException when i try to access the Map

is there a way to debug the framework, everytime i use the debugger it dont step into the spring classes
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is there a way to debug the framework, everytime i use the debugger it dont step into the spring classes

Yes, but you need to have Spring source code in order to step into Spring classes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic