Spring 尝试动态创建bpmn20.xml文件时出错
严重:上下文初始化失败 java.lang.NoClassDefFoundError:org/activiti/bpmn/model/FlowElement 服务等级Spring 尝试动态创建bpmn20.xml文件时出错,spring,activiti,Spring,Activiti,严重:上下文初始化失败 java.lang.NoClassDefFoundError:org/activiti/bpmn/model/FlowElement 服务等级 package com.activiti.deploy.service; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOExcep
package com.activiti.deploy.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.activiti.bpmn.BpmnAutoLayout;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.EndEvent;
import org.activiti.bpmn.model.FormProperty;
import org.activiti.bpmn.model.ParallelGateway;
import org.activiti.bpmn.model.Process;
import org.activiti.bpmn.model.ScriptTask;
import org.activiti.bpmn.model.SequenceFlow;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.bpmn.model.UserTask;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.activiti.deploy.model.ActivitiForm;
@Service("ActivtiInterfaceService")
@Transactional
public class ActivitiInterfaceServiceImpl implements ActivtiInterfaceService{
public boolean deployinActiviti(ActivitiForm activitiForm) throws IOException{
boolean deployed = false;
BpmnModel model = new BpmnModel();
Process process = new Process();
model.addProcess(process);
process.setId("my-process");
process.setName("Qmplus test");
process.addFlowElement(createStartEvent());
process.addFlowElement(createUserTask("task1","First task","kermit",activitiForm));
process.addFlowElement(createUserTask("task2","Second task","kermit",activitiForm));
List<SequenceFlow> outgoing = new ArrayList<SequenceFlow>();
outgoing.add(createSequenceFlow("task3","task4"));
outgoing.add(createSequenceFlow("task3","task2"));
process.addFlowElement(createParallelTask("task3","option task",outgoing));
process.addFlowElement(createEndEvent());
process.addFlowElement(createScriptTask("task4","script task","12343"));
process.addFlowElement(createSequenceFlow("start","task1"));
process.addFlowElement(createSequenceFlow("task1","task3"));
process.addFlowElement(createSequenceFlow("task3","task2"));
process.addFlowElement(createSequenceFlow("task3","task4"));
process.addFlowElement(createSequenceFlow("task2","end"));
process.addFlowElement(createSequenceFlow("task4","end"));
// 2. Generate graphical information
new BpmnAutoLayout(model).execute();
/*DefaultHttpClient dhc = new DefaultHttpClient();
dhc.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials("kermit", "kermit"));
HttpPost hp = new HttpPost("http://localhost:8080/activiti-rest/service/deployment");
hp.addHeader( "Content-Type", "multipart/form-data; boundary=---------------------------28617237579832" );
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost("localhost", 8080, "http"), basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
MultipartEntity se = new MultipartEntity();
byte[] xml = new BpmnXMLConverter().convertToXML(model);
FileOutputStream fileOuputStream =
new FileOutputStream("target/test.bpmn20.xml");
fileOuputStream.write(xml);
fileOuputStream.close();
File file = new File("target/test.bpmn20.xml");
se.addPart("success", new StringBody("success", Charset.forName("UTF-8")));
se.addPart("failure", new StringBody("failure", Charset.forName("UTF-8")));
FileBody fileBody = new FileBody(file);
se.addPart("deployment", fileBody);
hp.setEntity(se);
// HttpResponse processResponse = dhc.execute(hp,localcontext);
//String data=IOUtils.toString(processResponse.getEntity().getContent());
//System.out.println("reader"+data);
// dhc.getConnectionManager().shutdown(); */
return deployed;
}
protected UserTask createUserTask(String id, String name, String assignee, ActivitiForm activitiForm)
{
UserTask userTask = new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(assignee);
List<FormProperty> formProperties = new ArrayList<FormProperty>();
formProperties.add(createFormProperty(activitiForm));
userTask.setFormProperties(formProperties);
return userTask;
}
protected FormProperty createFormProperty(ActivitiForm activitiForm){
FormProperty formproperty = new FormProperty();
formproperty.setName(activitiForm.getTitle());
formproperty.setType(activitiForm.getType());
return formproperty;
}
protected SequenceFlow createSequenceFlow(String from, String to)
{
SequenceFlow flow = new SequenceFlow();
flow.setSourceRef(from);
flow.setTargetRef(to);
return flow;
}
protected ParallelGateway createParallelTask(String id, String name, List<SequenceFlow> outgoingFlows)
{
ParallelGateway p = new ParallelGateway();
p.setId(id);
p.setName(name);
p.setOutgoingFlows(outgoingFlows);
return p;
}
protected ScriptTask createScriptTask(String id, String name, String script)
{
ScriptTask st = new ScriptTask();
st.setId(id);
st.setScript("out.println(" + script + ")");
st.setScriptFormat("groovy");
st.setName(name);
return st;
}
protected StartEvent createStartEvent()
{
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
return startEvent;
}
protected EndEvent createEndEvent()
{
EndEvent endEvent = new EndEvent();
endEvent.setId("end");
return endEvent;
}
}
package com.activiti.deploy.service;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.net.HttpURLConnection;
导入java.nio.charset.charset;
导入java.util.ArrayList;
导入java.util.List;
导入org.activiti.bpmn.BpmnAutoLayout;
导入org.activiti.bpmn.converter.BpmnXMLConverter;
导入org.activiti.bpmn.model.BpmnModel;
导入org.activiti.bpmn.model.EndEvent;
导入org.activiti.bpmn.model.FormProperty;
导入org.activiti.bpmn.model.ParallelGateway;
导入org.activiti.bpmn.model.Process;
导入org.activiti.bpmn.model.ScriptTask;
导入org.activiti.bpmn.model.SequenceFlow;
导入org.activiti.bpmn.model.StartEvent;
导入org.activiti.bpmn.model.UserTask;
导入org.springframework.stereotype.Service;
导入org.springframework.transaction.annotation.Transactional;
导入com.activiti.deploy.model.ActivitiForm;
@服务(“ActivtiInterfaceService”)
@交易的
公共类ActivitiInterfaceServiceImpl实现ActivitiInterfaceService{
public boolean deployinActiviti(ActivitiForm ActivitiForm)引发IOException{
布尔值=假;
BpmnModel model=新的BpmnModel();
流程=新流程();
模型。添加过程(过程);
process.setId(“我的进程”);
process.setName(“Qmplus测试”);
process.addFlowElement(createStarteEvent());
addFlowElement(createUserTask(“task1”、“第一个任务”、“kermit”、activitiForm));
addFlowElement(createUserTask(“task2”、“第二个task”、“kermit”、activitiForm));
列表传出=新建ArrayList();
添加(createSequenceFlow(“task3”、“task4”);
添加(createSequenceFlow(“task3”、“task2”));
addFlowElement(createParallelTask(“task3”,“选项任务”,传出));
process.addFlowElement(createEndEvent());
addFlowElement(createScriptTask(“task4”、“脚本任务”、“12343”);
process.addFlowElement(createSequenceFlow(“开始”,“任务1”));
process.addFlowElement(createSequenceFlow(“task1”、“task3”);
process.addFlowElement(createSequenceFlow(“task3”、“task2”);
process.addFlowElement(createSequenceFlow(“task3”、“task4”);
process.addFlowElement(createSequenceFlow(“task2”,“end”));
process.addFlowElement(createSequenceFlow(“task4”,“end”));
//2.生成图形信息
新的BpmnAutoLayout(model).execute();
/*DefaultHttpClient dhc=新的DefaultHttpClient();
setCredentialsProvider().setCredentials(新的AuthScope(AuthScope.ANY_主机、AuthScope.ANY_端口、AuthScope.ANY_域)、新的用户名密码凭据(“kermit”、“kermit”);
HttpPost hp=新的HttpPost(“http://localhost:8080/activiti-休息/服务/部署);
hp.addHeader(“内容类型”,“多部分/表单数据;边界=------------------------------------28617237579832”);
//创建AuthCache实例
AuthCache AuthCache=new BasicAuthCache();
//生成基本方案对象并将其添加到本地身份验证缓存
碱性血红素碱性血红素=新碱性血红素();
put(新的HttpHost(“localhost”,8080,“http”),basicAuth);
//将AuthCache添加到执行上下文
BasicHttpContext localcontext=新的BasicHttpContext();
setAttribute(ClientContext.AUTH\u缓存,authCache);
MultipartEntity se=新的MultipartEntity();
字节[]xml=新的BpmnXMLConverter().ConvertXML(模型);
FileOutputStream FileOutputStream=
新的FileOutputStream(“target/test.bpmn20.xml”);
write(xml);
fileOutStream.close();
File File=新文件(“target/test.bpmn20.xml”);
se.addPart(“成功”,新StringBody(“成功”,Charset.forName(“UTF-8”));
se.添加部件(“故障”,新的StringBody(“故障”,字符集名称(“UTF-8”));
FileBody FileBody=新的FileBody(文件);
se.addPart(“部署”,文件体);
hp.setEntity(se);
//HttpResponse processResponse=dhc.execute(hp,localcontext);
//字符串数据=IOUtils.toString(processResponse.getEntity().getContent());
//System.out.println(“读卡器”+数据);
//getConnectionManager().shutdown()*/
返回部署;
}
受保护的UserTask createUserTask(字符串id、字符串名称、字符串受让人、ActivitiForm ActivitiForm)
{
UserTask UserTask=new UserTask();
userTask.setName(name);
userTask.setId(id);
userTask.setAssignee(受让人);
List formProperties=new ArrayList();
添加(createFormProperty(ActivityForm));
setFormProperties(formProperties);
返回用户任务;
}
受保护的FormProperty createFormProperty(ActivitiForm ActivitiForm){
FormProperty FormProperty=新的FormProperty();
setName(activitiForm.getTitle());
setType(activitiForm.getType());
归还财产;
}
受保护的SequenceFlow CreateSquenceFlow(字符串从,字符串到)
{
SequenceFlow=新的SequenceFlow();
流量设置资源(来自);
flow.setTargetRef(到);
回流;
}
受保护的ParallelGateway createParallelTask(字符串id、字符串名称、列表输出流)
{
ParallelGateway p=新的ParallelGateway();
p、 setId(id);
p、 集合名(名称);
p、 设定支出流量(支出流量);
返回p;
}
受保护的ScriptTask createScriptTask(字符串id、字符串名称、字符串脚本)
{
ScriptTask st=新建ScriptTask();
圣塞迪德(id);
st.setScript(“out.println(“+script+”));
st.SetScript格式(“groovy”);
圣赛特名称(名称);
返回st;
}
受保护的StartEvent createStartEvent()
{
斯塔特
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpringActiviti</groupId>
<artifactId>ActivitiLearning</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ActivitiLearning Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<springFramework.version>4.2.0.RELEASE</springFramework.version>
<jackson.version>2.5.3</jackson.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springFramework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springFramework.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-layout</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>5.17.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>ActivitiLearning</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>ActivitiLearning</finalName>
</build>
<repositories>
<repository>
<id>Alfresco Maven Repository</id>
<url>https://maven.alfresco.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>