当前位置: 代码迷 >> Web前端 >> Activiti工作流配备在项目Web中的始化和销毁
  详细解决方案

Activiti工作流配备在项目Web中的始化和销毁

热度:426   发布时间:2012-08-24 10:00:20.0
Activiti工作流配置在项目Web中的始化和销毁

???????????????? 在项目启动的时候需要启动相关的activiti服务,在activiti通过使用servletcontextlistener实现在项目启动相关的服务。
package org.activiti.rest.servlet;

?

import java.util.logging.Level;

import java.util.logging.Logger;

?

import javax.servlet.ServletContextEvent;

import javax.servlet.ServletContextListener;

?

import org.activiti.engine.ProcessEngine;

import org.activiti.engine.ProcessEngines;

import org.activiti.engine.impl.util.LogUtil;

?

/**

?* @author Tijs Rademakers

?*/

public class ActivitiServletContextListener implements ServletContextListener {

?

? //Initialise logging

? static {

??? LogUtil.readJavaUtilLoggingConfigFromClasspath();

? }

?

? protected static final Logger LOGGER = Logger.getLogger(ActivitiServletContextListener.class.getName());

?

? public void contextInitialized(ServletContextEvent event) {

??? ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

??? if (processEngine == null) {

????? LOGGER.log(Level.SEVERE,"Could not start the Activiti Engine");

??? }

? }

?

? public void contextDestroyed(ServletContextEvent event) {

??? ProcessEngines.destroy();

? }

?

}

web.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>?

<web-app id="WebApp_ID" version="2.4"?

??????????? xmlns="http://java.sun.com/xml/ns/j2ee"?

??????????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?

??????????? xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee?

???????????????? http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">?

?

? <display-name>Activiti REST</display-name>

??

? <listener>

??? <listener-class>org.activiti.rest.servlet.ActivitiServletContextListener</listener-class>

? </listener>

?

? <!-- Restlet adapter -->?

? <servlet>?

??? <servlet-name>RestletServlet</servlet-name>?

??? <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>

??? <init-param>

????? <!-- Application class name -->

????? <param-name>org.restlet.application</param-name>

????? <param-value>org.activiti.rest.application.ActivitiRestApplication</param-value>

??? </init-param>

? </servlet>

?

? <!-- Catch all requests -->?

? <servlet-mapping>?

??? <servlet-name>RestletServlet</servlet-name>?

? ??<url-pattern>/service/*</url-pattern>?

? </servlet-mapping>?

</web-app>

?

  相关解决方案