[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[整理]activiti,版本5.19.0.2,整合rest接口到我的工程~~

上一篇:[整理]httpclient 4.5 使用连接池的写法。
下一篇:[备忘]之前去黄山的攻略:十一南京、黄山游6日游攻略,供参考吧~

添加日期:2016/4/15 10:10:28 快速返回   返回列表 阅读10612次

前提,我的工程是spring+spring mvc的,
已经配置好了activiti的各种service什么的。

整合过程参考了此文:
http://www.kafeitu.me/activiti/2015/12/27/integrate-new-activiti-modeler-and-rest.html

但配置文件写法和它不太一样,故费了好大劲。

(1)原activiti-rese的war包里,WEB-INF\classes下有个db.properties,
里面的配置就是为了创建dataSource用的,我的工程里已经有了dataSource,故无视这个文件即可。

(2)WEB-INF\classes下有个engine.properties,内容如下
-----------
# demo data properties
create.demo.users=true
create.demo.definitions=true
create.demo.models=true

# engine properties
engine.schema.update=true
engine.activate.jobexecutor=false
engine.asyncexecutor.enabled=true
engine.asyncexecutor.activate=true
engine.history.level=full

# rest properties

# Enable/disable Java serializable objects to be passed as variables in the REST API.
rest.variables.allow.serializable=true
-----------------------
第一段demo相关的,是否自动创建demo数据的,无视即可
第二段是processEngine设置参数的,我也无视了。

(3)原war包用了全注解。
---------------------------------------
(1)POM增加jar包依赖


        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-rest</artifactId>
            <version>5.19.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-common-rest</artifactId>
            <version>5.19.0.2</version>
        </dependency>


(2)spring的applicationContext.xml中增加配置,扫描org.activiti.rest包以下的service类。


    <!-- 扫描组件 -->
    <context:component-scan base-package="com.xxx.yyyy,org.activiti.rest">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>


(3)增加spring-mvc-rest.xml,和咖啡兔的文章一样。


<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- 自动扫描且只扫描@Controller -->
    <context:component-scan base-package="org.activiti.rest">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <mvc:annotation-driven />
</beans>


(4)配置Servlet映射,和咖啡兔的文章一样


<servlet>
    <servlet-name>RestServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-mvc-rest.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>RestServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>



(5)最重要的一点,在applicationContext.xml里除了7大接口,还要增加bean声明


    <bean id="restResponseFactory" class="org.activiti.rest.service.api.RestResponseFactory"/>
    <bean id="resolver" class="org.activiti.rest.common.application.DefaultContentTypeResolver"/>


没加的时候,一堆错,反编译看了rest包的类,才知道要定义这两个东西。

(6)我用的shiro,所以在shiro配置文件里加
/rest/** = anon
允许匿名访问。

(7)咖啡兔文章里的:Rest安全认证组件,我没加,也没事。
不过现在访问rest接口不要base认证,好奇怪。
我再研究研究~~
 

评论 COMMENTS
guest438283641
2016/4/18 21:18:52
你能发下你的配置吗

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved