I am trying to get a simple Spring example to work with Activiti 5.5 and with some problems. I use a process engine configured with activiti in% activiti_home% / apps / apache-tomcat-6.0.32 / webapps / activiti-rest.
I modified the Spring configuration file to include my custom Spring configuration file:
<import resource="classpath*:applicationContext*.xml"/>
I deployed the applicationContext.xml file to the activiti-rest / WEB-INF / classes folder. Activiti starts up fine, and I see System.out.println in my bean constructor, so I know that my Spring configuration is read and built by a bean. I created a Spring bean for a class that implements JavaDelegate and introduced a bean to me, and it is always null.
Here is my Spring Config:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean id="myBean" class="org.bpmn.examples.MyBean"/> <bean id="taskBean" class="org.bpmn.examples.GetBeanTest"> <property name="myBean" ref="myBean"/> </bean> </beans>
Here is my Bean:
package org.bpmn.examples; import java.io.Serializable; public class MyBean implements Serializable { public MyBean() { super(); System.out.println("<========================== myBean ===========================>"); System.out.println("<========================== myBean ===========================>"); System.out.println("<========================== myBean ===========================>"); } private static final long serialVersionUID = -2867207654072787909L; Long id; String description; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }
Here is my class that implements JavaDelegate:
package org.bpmn.examples; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.delegate.JavaDelegate; public class GetBeanTest implements JavaDelegate { private MyBean myBean; @Override public void execute(DelegateExecution execution) throws Exception { if(myBean == null){ System.out.println("Bean was null!"); }else{ System.out.println("Bean is valid!"); } } public void setMyBean(MyBean myBean) { this.myBean = myBean; } }
All this seems quite simple to me, however, I think the problem is that Activiti does not use Spring bean in the class that is called in my JavaService task, it creates a new instance.
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test"> <process id="TestSpringConfig" name="TestSpringConfig"> <documentation>Place documentation for the 'TestSpringConfig' process here.</documentation> <startEvent id="startevent1" name="Start"></startEvent> <serviceTask id="servicetask1" name="BeanTest" activiti:class="org.bpmn.examples.GetBeanTest"></serviceTask> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow> <sequenceFlow id="flow2" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow> </process> </definitions>
How can I get a link to a Spring bean, either simple, like mine, or one that was configured as a JPA object?
Any / all answers are appreciated!
6.28.2011 Updated: When I tried to change the activiti-rest application to use SpringProcessEngineConfiguration instead of the standalone StandaloneProcessEngineConfiguration, I changed the activiti-cfg.xml file in the activiti-cfg.jar file and restarted Tomcat.
I am modifying the xml file to look like this:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="org.h2.Driver" /> <property name="url" value="jdbc:h2:tcp://localhost/activiti" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"/> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="dataSource" /> <property name="transactionManager" ref="transactionManager" /> <property name="databaseSchemaUpdate" value="true" /> <property name="jobExecutorActivate" value="false" /> </bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration" /> </bean> <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" /> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" /> <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" /> <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" /> <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" /> </beans>
When I restarted Tomcat, no exceptions appear, however, when I call Explorer and try to log in, I get the following exception:
INFO: Server startup in 12011 ms 10:32:02,338 ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 05280000 Wrapped Exception (with status template): null org.springframework.extensions.webscripts.WebScriptException: 05280000 Wrapped Exception (with status template): null at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:742) at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:167)