Results 1 to 5 of 5

Thread: afterPropertiesSet()

  1. #1
    Join Date
    Aug 2005
    Location
    Sydney,Australia
    Posts
    11

    Default 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
    Abhijeet Rai
    Java Analyst Programmer

  2. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default Re: afterPropertiesSet()

    Quote 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.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    +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.

  4. #4
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote 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.

  5. #5
    Join Date
    Aug 2005
    Location
    Sydney,Australia
    Posts
    11

    Default

    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
    Abhijeet Rai
    Java Analyst Programmer

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. Replies: 1
    Last Post: Mar 16th, 2005, 09:51 AM
  4. Replies: 2
    Last Post: Feb 11th, 2005, 11:09 AM
  5. Replies: 13
    Last Post: Dec 7th, 2004, 10:00 AM

Posting Permissions

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