Spring restful 配置


1. 使用maven  添加jar支持

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-xc</artifactId>
    <version>1.9.13</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>apache-cxf</artifactId>
    <version>2.2.8</version>
    <type>pom</type>
</dependency>

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>2.2.8</version>
</dependency>

<dependency>
    <groupId>com.sun.jersey.samples</groupId>
    <artifactId>jacksonjsonprovider</artifactId>
    <version>1.17</version>
</dependency>

<dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
</dependency>

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.2</version>
</dependency>

2. web.xml 配置


<servlet>
   <servlet-name>CXFServlet</servlet-name>
   <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>CXFServlet</servlet-name>
   <url-pattern>/restful/*</url-pattern>
</servlet-mapping>



3. spring-rpc.xml

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />


<bean id="Api" class="com.test.impl.ApiImpl" />
<jaxrs:server id="apiInterface" address="/apiInterface">
       <jaxrs:extensionMappings>
              <entry key="json" value="application/json" />
              <entry key="xml" value="application/xml" />
       </jaxrs:extensionMappings>
       <jaxrs:serviceBeans>
              <ref bean="api" />
       </jaxrs:serviceBeans>
       <jaxrs:providers>
              <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
       </jaxrs:providers>
</jaxrs:server>


4. 接口

@POST
@Path("/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
String test(Map<String,String> paramMap) throws Exception;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值