aspose file tools*
The moose likes Spring and the fly likes Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container" Watch "Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container" New topic
Author

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

hisham ragheb
Ranch Hand

Joined: Apr 14, 2008
Posts: 30
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


SCJP 1.5 (94%), SCWCD 1.4 (91%), SCBCD 1.5 (95%)
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Moving to Application Frameworks forum.

[My Blog] [JavaRanch Journal]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Without any code or configuration I don't see how anybody could help.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moving to Spring.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
You should have a Map bean specified.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
hisham ragheb
Ranch Hand

Joined: Apr 14, 2008
Posts: 30
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

Joined: Jul 05, 2005
Posts: 1936
Please post your configuration.
hisham ragheb
Ranch Hand

Joined: Apr 14, 2008
Posts: 30
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

Joined: Jul 05, 2005
Posts: 1936
There is no Map bean. You need a Map bean.
hisham ragheb
Ranch Hand

Joined: Apr 14, 2008
Posts: 30
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

Joined: Sep 11, 2006
Posts: 959



SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
hisham ragheb
Ranch Hand

Joined: Apr 14, 2008
Posts: 30
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

Joined: Sep 11, 2006
Posts: 959


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
 
subject: Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container