• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Application Frameworks forum.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without any code or configuration I don't see how anybody could help.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Spring.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should have a Map bean specified.
 
hisham ragheb
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your configuration.
 
hisham ragheb
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no Map bean. You need a Map bean.
 
hisham ragheb
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
hisham ragheb
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic