zoukankan      html  css  js  c++  java
  • REST架构之Apache Wink

    Apache Wink是一个使用简单,稳定的Java框架,用于创建RESTful web services应用程序。Wink包括了一个服务器端模块和一个客户端模块,用于帮助开发者快速高效的开发RESTful Web services应用。

    首先,需要在web.xml里面配置一下,把REST的访问都安排给Wink来处理。代码如下:

      <servlet>
        <servlet-name>restSdkService</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>restSdkService</servlet-name>
        <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>

    与Spring无缝集成

    集成模块wink-spring-support,配置如下:

      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:META-INF/server/wink-core-context.xml
            classpath:conf/spring-bean.xml
    classpath:conf/spring-dataSource.xml
    </param-value>
    </context-param>

    其中wink-core-context.xml是wink-spring-support模块里面的一个Spring配置文件,spring-bean.xml配置如下:

    <bean class="org.apache.wink.spring.Registrar">
            <property name="classes">
                <set value-type="java.lang.Class"></set>
            </property>
            <property name="instances">
                <set>
                    <ref local="userRest" />
                    <ref local="noticeRest" />
                    <ref local="searchRest" />
                    <ref local="voteRest" />
                    <ref local="resourceRest" />
                    <ref local="sysManageRest" />
                </set>
            </property>
        </bean>
    
        <bean id="userRest" class="rest.UserRest">
        </bean>

    HelloWorldResource是一个REST里面的Resource,用Annotation配置路径等信息:

    import javax.ws.rs.GET;  
    import javax.ws.rs.Path;  
      
    import org.apache.wink.common.annotations.Workspace;  
      
    @Workspace(workspaceTitle = "Workspace Title", collectionTitle = "Collection Title")  
    @Path("/user")  
    public class UserRest{  
      
        @GET  
        public String login() {  
            return "ok";  
        }  
    }

    以前,是用的cfx方式发布的restful服务。

  • 相关阅读:
    什么是 rel="shortlink" ?
    HTML5 怎么兼容 XHTML
    Connection to `ssl://pecl.php.net:443' failed: mac系统
    记录小程序中经常犯的错误---在wxml中使用js方法(打脸不)
    从js对象数组中删除某一个对象
    彻底搞懂字符串提取方法 slice,substr,substring
    vue 项目中笔记-持续更新
    CF526G Spiders Evil Plan
    BZOJ2178 圆的面积并
    计算几何入门
  • 原文地址:https://www.cnblogs.com/ld-swust/p/6117760.html
Copyright © 2011-2022 走看看