如何使用Spring发布REST Web服务?

时间:2014-07-24 07:22:28

标签: java spring cxf jax-rs

我有SOAPCXF网络服务,并通过以下方式发布Spring

应用context.xml中:

<jaxws:endpoint implementor="de.test.MyService" address="/MyService" />

REST服务的等价物是什么?

2 个答案:

答案 0 :(得分:1)

CXF 2.7.3

<bean id="restService" class="de.test.MyServiceRest" />

<jaxrs:server id="restServiceCXF" address="/MyServiceRest">
       <jaxrs:serviceBeans>
             <ref bean="restService" />
       </jaxrs:serviceBeans>
</jaxrs:server>

json版本

    <jaxrs:server id="restServiceCXF" address="/MyServiceRest">
         <jaxrs:serviceBeans>
              <ref bean="restService" />
         </jaxrs:serviceBeans>
         <jaxrs:providers>
            <ref bean='jsonProvider' />
        </jaxrs:providers>
    </jaxrs:server>

<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/>

xml版

    <jaxrs:server id="restServiceCXF" address="/MyServiceRest">
         <jaxrs:serviceBeans>
              <ref bean="restService" />
         </jaxrs:serviceBeans>
         <jaxrs:providers>
            <ref bean='jaxbProvider' />
        </jaxrs:providers>
    </jaxrs:server>

<bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>

答案 1 :(得分:0)

<jaxrs:server serviceClass="de.test.MyServiceRest" address="/MyServiceRest" />