我正在使用Apache Karaf、CXF和Aries Blueprint。
我有一个定义了许多JAX-RS服务的包。默认情况下,CXF将使这些服务成为单例,但这对我来说不起作用。我需要一个新的实例来处理每个请求。
参考CXF文档,我尝试创建返回服务新实例的JAX-RS ServiceFactories。文档中有Spring的例子,我试着用Blueprint来代替。<reference id="groupService" interface="org.ozoneplatform.owf.server.service.api.GroupService"/>
<bean id="groups" class="org.ozoneplatform.owf.server.rest.GroupController" scope="prototype">
<property name="service" ref="groupService"/>
</bean>
<bean id="groupFactory" class="org.apache.cxf.blueprint.jaxrs.BlueprintResourceFactory">
<property name="beanId" value="groups" />
</bean>
<jaxrs:server id="ozoneplatform_cxf_endpoint" address="/owf">
<jaxrs:serviceFactories>
<ref bean="groupFactory" />
</jaxrs:serviceFactories>
Blueprint启动失败,给出错误
org.osgi.service.blueprint.container.ComponentDefinitionException:
Error setting property: PropertyDescriptor <name: resourceProviders, getter: null, setter: [class org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setResourceProviders(interface java.util.List)]
您必须为BlueprintResourceFactory实例定义"blueprintContainer"属性:
<bean id="groupFactory" class="org.apache.cxf.blueprint.jaxrs.BlueprintResourceFactory">
<property name="beanId" value="groups" />
<property name="blueprintContainer" ref="blueprintContainer"/>
</bean>
其中ref="blueprintContainer"是对顶层管理器的引用(参见121.11 Blueprint Container)