码迷,mamicode.com
首页 > 编程语言 > 详细

配置 cxf-rs spring bean 文件

时间:2016-08-02 22:19:12      阅读:531      评论:0      收藏:0      [点我收藏+]

标签:

http://cxf.apache.org/schemas/jaxrs.xsd

http://cxf.apache.org/docs/restful-services.html

示例:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:cxf="http://cxf.apache.org/core"
       
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
           http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
                          ">
<import resource="classpath:META-INF/cxf/cxf.xml" /> <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" /> <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /> <cxf:bus> <cxf:features> <cxf:logging /> </cxf:features> </cxf:bus> <jaxrs:server id="services" address="/"> <jaxrs:serviceBeans> <bean class="cn.zno.HelloWorld" /> </jaxrs:serviceBeans> <jaxrs:providers> <ref bean="jsonProvider" /> <ref bean="jaxbProvider" /> </jaxrs:providers> <jaxrs:extensionMappings> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </jaxrs:extensionMappings> <jaxrs:languageMappings> <entry key="en" value="en-gb" /> </jaxrs:languageMappings> </jaxrs:server> </beans>

没有endpoint

<xsd:element name="server">...</xsd:element>
<xsd:element name="client">...</xsd:element>

jaxrs:server

<xsd:attributeGroup ref="cxf-beans:beanAttributes"/>
<xsd:attribute name="address" type="xsd:string"/>
<xsd:attribute name="bus" type="xsd:string"/>
<xsd:attribute name="serviceClass" type="xsd:string"/>
<xsd:attribute name="transportId" type="xsd:string"/>
<xsd:attribute name="modelRef" type="xsd:string"/>
<xsd:attribute name="bindingId" type="xsd:string"/>
<xsd:attribute name="staticSubresourceResolution" type="xsd:boolean"/>
<xsd:attribute name="beanNames" type="xsd:string"/>
<xsd:attribute name="serviceName" type="xsd:QName"/>
<xsd:attribute name="docLocation" type="xsd:string"/>
<xsd:attribute name="publishedEndpointUrl" type="xsd:string"/>
<xsd:attribute name="basePackages" type="xsd:string"/>
<xsd:attribute name="serviceAnnotation" type="xsd:string"/>
<xsd:attribute name="publish" type="xsd:boolean"/>

 

<xsd:all>
<xsd:element name="executor" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="features" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="binding" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="dataBinding" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="inFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="invoker" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="serviceFactories" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="outInterceptors" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="outFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="properties" type="beans:mapType" minOccurs="0"/>
<xsd:element name="serviceBeans" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="modelBeans" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="model" type="model" minOccurs="0"/>
<xsd:element name="providers" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="extensionMappings" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="languageMappings" type="xsd:anyType" minOccurs="0"/>
<xsd:element name="schemaLocations" type="schemasType" minOccurs="0"/>
<xsd:element name="resourceComparator" type="xsd:anyType" minOccurs="0"/>
</xsd:all>

开启日志

    <cxf:bus>
        <cxf:features>
            <cxf:logging />
        </cxf:features>
    </cxf:bus>

增加后,请求时,增加如下日志:
七月 30, 2015 2:32:26 下午 org.apache.cxf.interceptor.LoggingInInterceptor
信息: Inbound Message
----------------------------
ID: 1
Address: http://localhost:8080/cxf-jaxrs-service/hello/jsonBean
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/json
Headers: {Accept=[application/json], cache-control=[no-cache], connection=[keep-alive], Content-Length=[28], content-type=[application/json], host=[localhost:8080], pragma=[no-cache], user-agent=[Apache CXF 3.1.1]}
Payload: {"val2":null,"val1":"Maple"}
--------------------------------------
七月 30, 2015 2:32:26 下午 org.apache.cxf.interceptor.LoggingOutInterceptor
信息: Outbound Message
---------------------------
ID: 1
Response-Code: 200
Content-Type: application/json
Headers: {Content-Type=[application/json], Date=[Thu, 30 Jul 2015 06:32:26 GMT]}
Payload: {"val2":"Maple","val1":"Maple"}
--------------------------------------

效果等同于:

<bean id="inInterceptors" class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
<bean id="outInterceptors" class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>

[...]

<jaxrs:inInterceptors>
  <ref bean="inInterceptors" />
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
  <ref bean="outInterceptors" />
</jaxrs:outInterceptors>

权限验证

http://cxf.apache.org/docs/security.html

 

配置 cxf-rs spring bean 文件

标签:

原文地址:http://www.cnblogs.com/zno2/p/4689362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!