Announcement Announcement Module
Collapse
No announcement yet.
paramters for a method in init-method attribute Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      how??

      Comment


      • #4
        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.

        Comment


        • #5
          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);
          }

          Comment

          Working...
          X