wood burning stoves 2.0*
The moose likes Spring and the fly likes Inheritance in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Inheritance in Spring" Watch "Inheritance in Spring" New topic
Author

Inheritance in Spring

Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Please see the below code,

I have two classes Person and Student, such a way that Student extends Person.

Person class


Student class


and my configuration file is as follows


and now through my client, I'm expecting to instantiate Student bean through IoC and need to display the id, name and class. But unfortunately, I'm able to display only the class name.




From the output, I observe that the constructor of Person is invoked when IoC instantiates Student as expected. But when I try displaying the ID and Name, they are displayed as null. Doesn't Spring container assign the values for parent object, before setting them to child object.



Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Schandha Ravi wrote:From the output, I observe that the constructor of Person is invoked when IoC instantiates Student as expected. But when I try displaying the ID and Name, they are displayed as null. Doesn't Spring container assign the values for parent object, before setting them to child object.

Spring doesn't know anything unless you tell it. That is those are just two beans spring instantiates. I haven't tried it but check this


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Thank you Vijitha Kumara.
Tomas Bilek
Greenhorn

Joined: Nov 17, 2011
Posts: 5
You must fill attribute "parent". So for example parent="Person".

Good Luck !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance in Spring
 
Similar Threads
Error creating bean
nested exception is org.xml.sax.SAXParseException: Attribute "value" must be declared
Understand regarding REQUIRED and REQUIRES_NEW
Spring Related-- @Autowired with Map<String, myObjectType> is not initialized in the IoC container
problem with hibernate integration