我想在春天使用 resteasy 和 jax-rs 创建一个 rest api。为此,以下几行是我的应用程序上下文的一部分:
<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>
在组件扫描期间,当我找到第一个休息接口 bean 时,这会在组件扫描期间导致 npe:
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
调试器显示resteasyregistry bean 和resteasyproviderfactory bean 都被解析为null。
谁能解释这是怎么发生的?作为测试,我更改了 xml,因此将注册表和工厂设置为属性,但即使在调用 setter 时,注册表和工厂也为空。
* EDIT2:弹簧调试日志*
这里是spring调试日志中的相关部分。
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'