Announcement Announcement Module
No announcement yet.
Prototype object in spring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prototype object in spring

    I used spring 2.5.
    I create a class "SalesServiceImpl" and i configered in .xml as prototype.

    <bean id="salesService"
    class=" pl.SalesServiceImpl" scope="prototype">
    <property name="salesDao" ref="salesDaoTarget"></property>
    <property name="batchService" ref="batchServ"></property>

    Then i print the hashCode value of .salesService, each time i get the same value, that means this object is not a prototype.

    So how can i create a prototype object in spring?

  • #2
    hashCode() implementation?

    Hi Aju,

    Can you provide the hashCode() implementation present in your bean?
    It is possible to have multiple instances of same class to have same hash code.

    For example --->

    public int hashCode() {
    return 10;

    For every instance of this class, hashcode will be 10.

    If you want to check whether a new instance has been created or not by the container, when ever you do getBean() sort of thing, then put a SOP with "this" - it will show the object reference. Make sure that you don't have a toString() implementation in your class.