Announcement Announcement Module
Collapse
No announcement yet.
Circular Reference Problem with JaxWsPortProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Circular Reference Problem with JaxWsPortProxyFactoryBean

    We recently upgraded to Spring 3.1, and replaced our XML configuration with Java Config. The biggest parts of our configuration were web service ports using JaxWsPortProxyFactoryBean. We wanted to translate these into Java Configuration beans in such a way that we could use the @Profile annotation to selectively turn ports on or off. For each web service we consume, we created a class using the following template:

    Code:
    @Service("webServicePort")
    public class WebServicePortTypeFactory extends JaxWsPortProxyFactoryBean {
    	
    	@Autowired
    	public WebServicePortTypeFactory(CredentialProperties credentials, WSDLProperties wsdl) {
    		super();
    		setWsdlDocumentUrl(wsdl.getWsdlDocumentUrl());
    		setNamespaceUri("http://my.namespace.uri/");
    		setServiceName("WebService");
    		setServiceInterface(WebServiceSoap.class);
    		setPortName("WebServiceSoap");
    		afterPropertiesSet();
    	}
    }
    Each of these ports is @Autowired into a service like this:

    Code:
    @Service("WebService")
    public class WebServiceImpl implements WebService {
    
    	@Autowired
    	WebServiceSoap webService;
    
         public String operation() {
              return webService.operation();
         }
    }
    Which is wired into a controller like this:

    Code:
    @Controller
    @RequestMapping("/web")
    public class WebController {
    	@Autowired
    	WebService webService;
    	
    	@Autowired
    	WSDLProperties props;
    	
    	@RequestMapping(value = "/service", method = RequestMethod.POST)
    	public @ResponseBody void service(@RequestBody Account account)
    			throws Exception {		
    		webService.operation();
    	}
    }
    With this setup, we seem to be encountering intermittent memory problems. Seemingly innocuous changes cause what looks like a circular dependency error in our ports:

    Code:
    Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'webPortType': Requested bean is currently in creation: Is there an unresolvable circular reference?
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:353)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
    Looking through the code, I do not see any circular references. Is there a preferred way to use JaxWsPortProxyFactoryBean with Java Config? Could there be a race condition with the way things are being @Autowired? If so, how could we prevent it?

    Thanks in advance for any help you can provide. Working with Java Config is an absolute pleasure, but some of these problems are frustratingly difficult to debug.

    Joe

  • #2
    You haven't converted it to java config beans you made it a service. I would (probably) create a @Configuration annotated class which does the same as your @Service bean (which also misses the @Profile annotation I guess).

    Also you shouldn't be calling afterPropertiesSet yourself, spring will detect the interfaces on the bean and call it for you.

    Could you post your original xml configuration so that we an see what you intend to do.

    Comment

    Working...
    X