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服务。

  • 相关阅读:
    ‘Found duplicate PV’ warnings when using LVM with multipath storage in RHEL/CentOS
    如何卸载windows的服务?卸载服务
    富文本wangeditor层级太高覆盖问题
    vue wangeditor
    vue消息提示this.$message方法
    MySQL之查询指定时间的数据
    企业微信第三方应用PC端实现用户点击注册的三种方式
    两款不带广告的輸入法
    jquery、css 的选择器
    广信可视电话设置可安装应用权限
  • 原文地址:https://www.cnblogs.com/ld-swust/p/6117760.html
Copyright © 2011-2022 走看看