Results 1 to 5 of 5

Thread: Retrieving a value from a running Bean as constructor argum

  1. #1
    Join Date
    Oct 2005
    Posts
    23

    Default Retrieving a value from a running Bean as constructor argum

    Hellu,

    I am trying to do the following:
    Get a static value through a static method out of a running bean and use this as a constructor arugment for a bean.
    I thought that I have to to this with "MethodInvokingFactoryBean", but it's not really working.
    How should I do this ?

    What I now have in my beans.xml:
    Code:
    	<bean id="WorkbenchWindowAdvisor" 
    		class="org.ited.mr.ui.core.impl.BasicWorkbenchWindowAdvisor" 
    		singleton="false" >
    		<constructor-arg ref="WorkbenchWIndowConfigurator"/>
    	</bean>
    
    	<bean id="WorkbenchWIndowConfigurator" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
       		<property name="targetClass"><value>org.ited.mr.ui.core.impl.BasicWorkbenchAdvisor</value></property>
       		<property name="targetMethod"><value>getConfigurator</value></property>
    	</bean>
    And the exception I get:
    org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'WorkbenchWindowAdvisor' defined in class path resource [beans.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.eclipse.ui.application.IWorkbenchWindowConfigu rer]: Could not convert constructor argument value [org.springframework.util.MethodInvoker$VoidType@1a 220e6] to required type [org.eclipse.ui.application.IWorkbenchWindowConfigu rer]:
    Please some advice on this issue ?

    Cheers,
    Ed

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Check out object retrieving from factory instances : http://static.springframework.org/sp...ns.html#d0e495

    <!-- The factory bean, which contains a method called
    createInstance -->
    <bean id="myFactoryBean"
    class="...">
    ...
    </bean>
    <!-- The bean to be created via the factory bean -->
    <bean id="exampleBean"
    factory-bean="myFactoryBean"
    factory-method="createInstance"/>
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Oct 2005
    Posts
    23

    Default

    Thanks for your reply costin.

    I tried it, and it almost worked... but I have the following problem:

    The bean that needs this object, that is created through the factory method, isn't yet initiated when the application start.

    However, when the application starts, Spring is loading all Spring beans in the xml file.

    I don't want this while the necessary constructor argument, that comes from the factory method, is still null (not yet initiated). You can overcome this intial loading of a bean with the attribute lazy-init. However this is only allowed for singletons. But my bean isn't a singleton....

    Any solotuion for this ??

    Cheers,
    Ed

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    But when you do you initialize your object? Also note that lazy-initialization applies on the bean no matter what type it is (singleton/prototype). You can use attribute depends-on if you depend on other beans unexplicitely (which are not injected).

    If your object is not ready when the application starts (have you looked at init="" attribute to force the initialization)) then how should Spring inject the property?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Oct 2005
    Posts
    23

    Default

    Hi Costin.
    Thankx

    The problem is that the property I need is from Eclipse. And eclipse will initialize this property when it makes a callback to a method of my object, and till now I have no control on that.
    So what happens is that I try to retrieve this property from my object, when the object is already alive and initialized, but eclipse didn't perform a callback and so I don't have the property, and so it's null.

    I will have a look if I can get the property from the eclipse parent object..... must be somewhere there already alive before it performs the call back..

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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