Results 1 to 2 of 2

Thread: Application Context set up for Java Inheritance

  1. #1

    Question Application Context set up for Java Inheritance

    Hi,

    Is it possible to configure inheritance in java in my applicationContext.xml

    Here is my java classes:

    Code:
    public class Bicycle
    {
         private String name;
         public getName(){return name;}
         public setName(String n){name=n;}
    }
    
    public class MountainBike extends Bicycle
    {
    }
    
    public class KidBike extends Bicycle
    {
    }
    Can someone show me how can I configure my application context to map this?

    I would like to set the property name as bean property.
    Code:
    <bean id="name" class="Bicycle">
    	<property name="name" value="ABC"/>
    </bean>

    Thanks,

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    It's not really clear what's not working for you. If you'd like to create a bean of type MountainBike, with the 'name' property set to "ABC", it's no problem:

    Here's how it would look with class Bicycle:

    Code:
    <bean id="bike" class="Bicycle">
    	<property name="name" value="ABC"/>
    </bean>
    And in the case of MountainBike:

    Code:
    <bean id="bike" class="MountainBike">
    	<property name="name" value="ABC"/>
    </bean>
    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •