Announcement Announcement Module
Collapse
No announcement yet.
Injecting the return value of a method into a bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by parmod
    How would I use this to inject value returned by the method from another bean?
    As Jörg Heinicke posted:

    Code:
    <bean factory-bean="myFactory" factory-method="getInstance">
      <constructor-arg value="propertyValue"/>
    </bean>
    so if you were wiring up aBean with a property theOtherBean then it would look like:

    Code:
    <bean id="aBean" class="....">
      <property name="theOtherBean">
        <bean factory-bean="myFactory" factory-method="getInstance">
          <constructor-arg value="propertyValue"/>
        </bean>
      </property>
    </bean>
    this would call aBean.setTheOtherBean after calling getInstance(propertyValue) on the bean named myFactory.

    Comment


    • #17
      If I do this

      Code:
       	    <property name="endPointUrl">
      	     	<bean factory-bean="IBusinessUnitClient" factory-method="getEndPointUrl"/>
      	    </property>
      It would be a circular dependency.

      Code:
      	<bean id="RequestAffiliateeWebService" class="com.netbet.affiliate.remote.client.BusinessUnitClientProxyFactoryBean" depends-on="IBusinessUnitClient">
      		<property name="serviceFactoryClass">
      			<value>org.apache.axis.client.ServiceFactory</value>
      		</property>
      		<property name="wsdlDocumentUrl">
      			<value>http://localhost:8080/bu-test/services/buwebservices?wsdl</value>
      		</property>
      		<property name="namespaceUri">
      			<value>http://localhost:8080/bu-test/services/buwebservices</value>
      		</property>
      		<!--  Web Service endpoint. Client sends a SOAP message to the server at this location -->
      		<property name="endpointAddress">
      			<value>http://localhost:8080/bu-test/services/buwebservices</value>
      		</property>
      		<property name="serviceName">
      			<value>BUWebServicesService</value>
      		</property>
      		<property name="serviceInterface">
      			<value>com.netbet.affiliate.remote.client.IBusinessUnitWebService</value>
      		</property>
      		<property name="portName">
      			<value>buwebservices</value>
      		</property>
      		<property name="portInterface">
      			<value>com.netbet.affiliate.remote.client.IBusinessUnitWebServiceRemote</value>
      		</property>
      		<property name="lookupServiceOnStartup">
      			<value>false</value>
      		</property>
      	        <property name="endPointUrl">
       		        <bean factory-bean="IBusinessUnitClient" factory-method="getEndPointUrl"/>
      	        </property>
      	</bean>
      
      	<bean id="IBusinessUnitClient" class="com.netbet.affiliate.facade.BusinessUnitClient">
      		
      		<property name="businessUnitDao">
      			<ref bean="IBusinessUnitDao"/>
      		</property>
      		<property name="activityRecordDao">
      			<ref bean="IActivityRecordDao"/>
      		</property>
      		<property name="affiliateeActivityDao">
      			<ref bean="IAffiliateeActivityDao"/>
      		</property>
      		<property name="requestAffiliateeWebService">
      			<ref bean="RequestAffiliateeWebService"/>
      		</property>
      	
      	</bean>
      Here is the exception
      Code:
      2006-08-30 11:08:07,312 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IBusinessUnitClient' defined in ServletContext resource [/WEB-INF/classes/spring/affiliate/affiliate-business.xml]: Cannot resolve reference to bean 'RequestAffiliateeWebService' while setting bean property 'requestAffiliateeWebService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'RequestAffiliateeWebService': Requested bean is currently in creation: Is there an unresolvable circular reference?
      org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'RequestAffiliateeWebService': Requested bean is currently in creation: Is there an unresolvable circular reference?
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:206)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:186)
      	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:760)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:571)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:414)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:360)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:152)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:247)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:331)
      	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:155)
      	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
      	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
      	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
      	at com.caucho.server.webapp.Application.start(Application.java:1597)
      	at com.caucho.server.deploy.DeployController.startImpl(DeployController.java:621)
      	at com.caucho.server.deploy.StartAutoRedeployAutoStrategy.startOnInit(StartAutoRedeployAutoStrategy.java:72)
      	at com.caucho.server.deploy.DeployController.startOnInit(DeployController.java:509)
      	at com.caucho.server.deploy.DeployContainer.start(DeployContainer.java:158)
      	at com.caucho.server.webapp.ApplicationContainer.start(ApplicationContainer.java:652)
      	at com.caucho.server.host.Host.start(Host.java:385)
      	at com.caucho.server.deploy.DeployController.startImpl(DeployController.java:621)
      	at com.caucho.server.deploy.StartAutoRedeployAutoStrategy.startOnInit(StartAutoRedeployAutoStrategy.java:72)
      	at com.caucho.server.deploy.DeployController.startOnInit(DeployController.java:509)
      	at com.caucho.server.deploy.DeployContainer.start(DeployContainer.java:158)
      	at com.caucho.server.host.HostContainer.start(HostContainer.java:501)
      	at com.caucho.server.resin.ServletServer.start(ServletServer.java:977)
      	at com.caucho.server.deploy.DeployController.startImpl(DeployController.java:621)
      	at com.caucho.server.deploy.AbstractDeployControllerStrategy.start(AbstractDeployControllerStrategy.java:56)
      	at com.caucho.server.deploy.DeployController.start(DeployController.java:517)
      	at com.caucho.server.resin.ResinServer.start(ResinServer.java:485)
      	at com.caucho.server.resin.Resin.init(Resin.java)

      Thanks

      Originally posted by yatesco
      As Jörg Heinicke posted:

      Code:
      <bean factory-bean="myFactory" factory-method="getInstance">
        <constructor-arg value="propertyValue"/>
      </bean>
      so if you were wiring up aBean with a property theOtherBean then it would look like:

      Code:
      <bean id="aBean" class="....">
        <property name="theOtherBean">
          <bean factory-bean="myFactory" factory-method="getInstance">
            <constructor-arg value="propertyValue"/>
          </bean>
        </property>
      </bean>
      this would call aBean.setTheOtherBean after calling getInstance(propertyValue) on the bean named myFactory.

      Comment


      • #18
        Well, if RequestAffiliateeWebService already depends on IBusinessUnitClient why not simply pass in IBusinessUnitClient in the constructor and at the end of the constructor call IBusinessUnitClient.getXYZ(). Or call it in the setIBusinessUnitClient(IBusinessUnitClient client) method?

        Comment


        • #19
          Originally posted by parmod
          Here is the configuration
          Code:
          	<bean id="MyBusinessUnit" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
          	  <property name="targetObject">
          	  	<ref bean="IBusinessUnitClient"/>
          	  </property>
          	  <property name="targetMethod" value="getEndPointUrl"/>
          	</bean>
          
          	<bean id="MyBusinessUnitProxy" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
          	  <property name="targetObject">
          	  	<ref bean="RequestAffiliateeWebService"/>
          	  </property>
          	  <property name="targetMethod" value="addEndpoint"/>
          	  	  <property name="arguments">
          	  		<list>
          	  			<ref bean="MyBusinessUnit"/>
          			</list>
          	  </property>	
          	</bean>
          The problem is, that you want to invoke the method on the _factory bean_. However, as configured, you try to invoke the method on the created proxy (which does not have this method).

          So try this:
          Code:
          <property name="targetObject">
           	<ref bean="&RequestAffiliateeWebService"/>
          </property>
          Note the ampersand, which tells Spring to refer the factory bean itself (maybe you have to XML-escape the '&').

          Regards,
          Andreas

          P.S.: as of the factory-method discussion: factory-methods are for creating instances (as extra feature besides direct constructor support). MethodInvokingFactoryBean could be used for this purpose as well, but serves a wider scope in invoking arbitrary methods not necessarily for construction purposes.

          Comment

          Working...
          X