Results 1 to 5 of 5

Thread: paramters for a method in init-method attribute

  1. #1
    Join Date
    Mar 2005
    Location
    India
    Posts
    95

    Default paramters for a method in init-method attribute

    hI,

    If we need to call a method that takes in a parameter(obj,primitive types) in the bean attibute : init-method

    hw do we do it??

    Regards

  2. #2

    Default

    Quote Originally Posted by A Kumar View Post
    hI,

    If we need to call a method that takes in a parameter(obj,primitive types) in the bean attibute : init-method

    hw do we do it??
    The initialization method cannot have parameters. If it has there should be an exception.

    It can have a return value which is ignored.

  3. #3
    Join Date
    Mar 2005
    Location
    India
    Posts
    95

    Default

    suppose we need to invoke a method ....lie init-method ..where in we need to pass few paramaters...

    how??

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

    Default

    You can create a FactoryBean for objects that are difficult to set up in Spring.

    But you can also use the MethodInvokingFactoryBean to deal with method invokes.

  5. #5
    Join Date
    Aug 2007
    Posts
    1

    Default

    If you are using this in a class you are writing, you could also inject all the properties that you need to pass to the method and have an init method that just forwards to the real method. eg.

    <bean id="foo" class="foo.bar" init-method="init">
    <property name="obj1" ref="beanObject" />
    <property name="primitiveVal" ref="17" />
    </bean>


    public void init(){
    yourMethod(obj1, primitiveVal);
    }

Posting Permissions

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