Announcement Announcement Module
Collapse
No announcement yet.
afterPropertiesSet() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • afterPropertiesSet()

    Springgers,

    Ok, a clarfication .

    for each property defined in the Spring defintion file we need to have setPropertyName in the implementing Class as well as afterPropertiesSet() ?

    If we dont have afterPropertiesSet() method then things dont work as expected , is it correct ?

    awaiting replies.

    Cheers
    Abhijeet

  • #2
    Re: afterPropertiesSet()

    Originally posted by abhirai
    Springgers,

    Ok, a clarfication .

    for each property defined in the Spring defintion file we need to have setPropertyName in the implementing Class
    I don`t completely understand what you are saying, but for every property xxx, you need a setxxx on your bean.

    [edit]
    so.. property age gives setter: setAge and getter getAge

    as well as afterPropertiesSet() ?
    This is not required. If you want your bean to be treated specially, you could implement the life cycle interface: InitializingBean

    Now spring knows that he can contact your bean and ask him if everything is ok after the properties are set.

    Personally I don`t like using properties and do everything by a constructor. I can give the guarantee that my object always is in a consistent state and I can`t give this guarantee if you use properties.

    Comment


    • #3
      +10 from me. Constructor args make it so much more obvious what requirements the class has. Unfortunately it requires a bit more xml to wire up the constructors as autowire by name cannot work, but I think it's worth it.

      Comment


      • #4
        Originally posted by yatesco
        +10 from me. Constructor args make it so much more obvious what requirements the class has. Unfortunately it requires a bit more xml to wire up the constructors as autowire by name cannot work, but I think it's worth it.
        Yes.. and with a constructor you don`t have the obligation to deal with changes that can occur if someone sets a property if the object is created some time ago and already in use. If there is no property to set, there is no obligation.

        Comment


        • #5
          Ok thanks Alarmnummer.

          I had lot of issue when not using afterPropertiesSet() method with a concept called Flow and Focus.

          If you look upon an application as a collection of flows and Each flow in turn is a sequence of focus and transfer of Listener objects happens from one focus to another using flowKeys which are java beans PropertyChangeListener in this framework.

          I hope i am making clear to you. I will keep in mind about Constructor args rather than using properties

          Cheers
          Abhijeet

          Comment

          Working...
          X