I want to create a rest api using reasteasy and jax-rs in spring. to do that the following lines are part of my application context:
<bean id="RESTeasyProviderFactory" class="org.springframework.web.context.support.ServletContextAttributeFactoryBean">
<property name="attributeName" value="org.jboss.resteasy.spi.ResteasyProviderFactory" />
</bean>
<bean id="RESTeasyRegistry" class="org.springframework.web.context.support.ServletContextAttributeFactoryBean">
<property name="attributeName" value="org.jboss.resteasy.spi.Registry" />
</bean>
<bean id="RESTeasyBeanPostProcessor" class="org.jboss.resteasy.plugins.spring.SpringBeanProcessor">
<constructor-arg>
<bean class="org.jboss.resteasy.core.AsynchronousDispatcher">
<constructor-arg ref="RESTeasyProviderFactory" />
</bean>
</constructor-arg>
<constructor-arg ref="RESTeasyRegistry" />
<constructor-arg ref="RESTeasyProviderFactory" />
</bean>
during the component scan this caused a npe during the component scan when my first rest interface bean is found:
Caused by: java.lang.NullPointerException
at org.jboss.resteasy.plugins.spring.SpringBeanProcessor$ResteasyBeanPostProcessor.getInjector(SpringBeanProcessor.java:133)
at org.jboss.resteasy.plugins.spring.SpringBeanProcessor$ResteasyBeanPostProcessor.postProcessAfterInitialization(SpringBeanProcessor.java:125)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 11 more
the debugger shows that the resteasyregistry bean and the resteasyproviderfactory bean are both resolved as null.
can anybody explain how this can happen?
as a test i changed the xml so the registry and the factory are set as properties but even there when the setter is called the registry and factory are null.
*EDIT2: spring debug log *
here the relevant part from the spring debug log.
2012-06-01 12:13:34,337 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'RESTeasyBeanPostProcessor'
2012-06-01 12:13:34,337 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'RESTeasyBeanPostProcessor'
2012-06-01 12:13:34,337 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.jboss.resteasy.core.AsynchronousDispatcher#e0380'
2012-06-01 12:13:34,340 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'RESTeasyProviderFactory'
2012-06-01 12:13:34,340 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'RESTeasyProviderFactory'
2012-06-01 12:13:34,340 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'RESTeasyProviderFactory' to allow for resolving potential circular references
2012-06-01 12:13:34,350 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'RESTeasyProviderFactory'
2012-06-01 12:13:34,386 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.jboss.resteasy.core.AsynchronousDispatcher#e0380'
2012-06-01 12:13:34,386 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'RESTeasyRegistry'
2012-06-01 12:13:34,386 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'RESTeasyRegistry'
2012-06-01 12:13:34,386 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'RESTeasyRegistry' to allow for resolving potential circular references
2012-06-01 12:13:34,386 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'RESTeasyRegistry'
2012-06-01 12:13:34,389 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'RESTeasyProviderFactory'
2012-06-01 12:13:34,393 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Eagerly caching bean 'RESTeasyBeanPostProcessor' to allow for resolving potential circular references
2012-06-01 12:13:34,393 DEBUG [main] o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'RESTeasyBeanPostProcessor'
I fixed this by writing my own singleton factories for the two beans. its annoying and should not be necessary, but it worked.
in the end we changed this part of the config totally so even this ugly solution became unnecessary.