Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3805

BeanInCreationException when CXF client factorybean used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.4.2
    • 2.4.3
    • JAX-WS Runtime
    • None
    • Unknown

    Description

      In complex spring context, when JaxWsProxyFactoryBean is used, context fails to start with BeanCurrentlyInCreationException.
      Part of exception:

      at org.springframework.context.support.AbstractApplicationContext.getBea
      nNamesForType(AbstractApplicationContext.java:1136)
      at org.apache.cxf.bus.spring.SpringBeanLocator.getBeansOfType(SpringBean
      Locator.java:89)
      at org.apache.cxf.bus.CXFBusImpl.getExtension(CXFBusImpl.java:99)
      at org.apache.cxf.service.factory.AbstractServiceFactoryBean.setBus(Abst
      ractServiceFactoryBean.java:98)
      at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.initializeSe
      rviceFactory(AbstractWSDLBasedEndpointFactory.java:232)
      at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoi
      nt(AbstractWSDLBasedEndpointFactory.java:100)
      at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.ja
      va:90)
      at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFact
      oryBean.java:153)
      at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBe
      an.java:151)

      ...
      Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: E
      rror creating bean with name 'testBeanBBO': org.springframework.beans.factory.Fa
      ctoryBeanNotInitializedException: FactoryBean is not fully initialized yet
      at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.
      doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:146)
      at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.
      getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:109)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getObje
      ctForBeanInstance(AbstractBeanFactory.java:1429)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
      an(AbstractBeanFactory.java:245)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
      (AbstractBeanFactory.java:190)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver
      .resolveReference(BeanDefinitionValueResolver.java:322)
      ... 133 more

      The main reason of the problem is that JaxWsProxyFactoryBean calls spring getBeanNamesForType, which
      needs to instantiate all spring beans - and it is very easy to reach the case, that in spring context
      in creation there are beans not fully initialized yet - and when getBeanNamesForType is called - BIG BUM - exception.

      It is not proper pattern to use spring getBeanNamesForType from FactoryBean.create method.

      I've tracked the problem and isolated simple test case - it is attached.
      Unpack it into apache-cxf-2.4.2-src\apache-cxf-2.4.2-src\systests\jaxws\src\test\java
      and run:
      mvn -Dtest=BeanInCreationExceptionTest test
      It fails for spring2 and spring3 as well.

      When you look at beans.xml, you will see that there are no circular dependencies which usually cause
      BeanCurrentlyInCreationException - but JaxWsProxyFactoryBean.create is making the problem.

      Just comment one line as below in beans.xml:
      <bean id="testBeanBBOImpl" class="org.apache.cxf.systest.beanincreationexception.TestBeanABOImpl">
      <property name="bean" ref="testBeanABO"/>
      <!-- <property name="client" ref="client2"/> -->
      </bean>

      and test runs ok.

      How to fix? Provide lighter version (or a switch) of JaxWsProxyFactoryBean - it can just create the proxy,
      and the rest (endpoint, client, all the stuff which requires getBeanNamesForType) can be instantiated later - for example in AfterpropertiesSet phase.
      Or avoid getBeanNamesForType if possible.

      Now the workaround we try, is to change the order of spring beans xml's and have a luck. Eventually changing from injecting client service/portType to
      getting them from applicationcontext.getBean - but it is not good practice.

      Attachments

        1. beanincreationexction.zip
          5 kB
          Tomasz Bech
        2. beanincreationexction.zip
          5 kB
          Tomasz Bech

        Activity

          People

            dkulp Daniel Kulp
            tomaszbech Tomasz Bech
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: