I follow exactly as JBPM Developers Guide session "16.3 Usage" to setup related XML. However, still cannot find the Spring Bean (my case is "TestCon" ).
The following are the XML and result.
***process.jpdl.xml(JBPM flow definition)***
<?xml version="1.0" encoding="UTF-8"?>
<process name="process" xmlns="http://jbpm.org/4.0/jpdl">
<start g="29,189,48,48" name="start">
<transition g="-74,-18" name="to doSomeThing" to="doSomeThing"/>
</start>
<java expr="#{TestCon}" method="createProduct" name="doSomeThing" g="178,89,80,40">
<transition to="printSomeThing"/>
</java>
<state g="383,196,111,52" name="printSomeThing">
<transition g="-23,-20" name="to end" to="end"/>
</state>
<end g="563,199,48,48" name="end"/>
</process>
******ApplicationContent-test.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: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-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ig_loading"/>
<property name="username" value="root"/>
<property name="password" value="admin123"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="dbDAO" class="Dao.ProductDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="productMan" class="Service.ProductManager">
<property name="productDAO" ref="dbDAO"/>
</bean>
<bean id="TestCont" class="Test">
<property name="managerProduct" ref="productMan"/>
</bean>
<bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
<constructor-arg value="jbpm.cfg.xml" />
</bean>
<bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
</beans>
*****Testing programe ****
import org.jbpm.api.Configuration;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.HistoryService;
import org.jbpm.api.ManagementService;
import org.jbpm.api.NewDeployment;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;
import org.jbpm.pvm.internal.env.Environment;
import org.jbpm.pvm.internal.env.SpringContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import POJO.Product;
import Service.ProductManager;
@Controller
public class Test{
//implements ApplicationContextAware
private ProductManager managerProduct;
private static ApplicationContext ac =null;
public static void main(String args[]){
ac = new ClassPathXmlApplicationContext(new String[] {"applicationContext-test.xml"});
Test test = new Test();
test.startUpJBPM();
}
public void startUpJBPM(){
ProcessEngine processEngine = new Configuration().buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
NewDeployment nd = repositoryService.createDeployment();
nd.addResourceFromClasspath("jpdl/process.jpdl.xml").deploy();
ProcessInstance processInstance = executionService.startProcessInstanceByKey("process");
}
public void createProduct(){
System.out.println("==== createProduct===");
managerProduct= (ProductManager) ac.getBean("productMan");
Product p = new Product();
p.setSku("0605");
p.setQuantity(04);
p.setSupplierCode("0605");
p.setIsMain(0);
managerProduct.addProduct(p);
}
public ProductManager getManagerProduct() {
return managerProduct;
}
public void setManagerProduct(ProductManager managerProduct) {
this.managerProduct = managerProduct;
}
}
**** running result ****
19:21:31,046 INFO SettingsFactory:296 - Default entity-mode: pojo
19:21:31,046 INFO SessionFactoryImpl:161 - building session factory
19:21:31,531 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
19:21:34,343 INFO DefaultCommandService:52 - exception while executing command org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd@181c4eb
org.jbpm.api.JbpmException: script evaluation error: Cannot find property TestCon
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:118)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:106)
at org.jbpm.pvm.internal.script.ScriptManager.evaluateExpression(ScriptManager.java:78)
at org.jbpm.jpdl.internal.activity.JavaActivity.perform(JavaActivity.java:68)
at org.jbpm.jpdl.internal.activity.JpdlAutomaticActivity.execute(JpdlAutomaticActivity.java:15)
at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperationSync(ExecutionImpl.java:637)
at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperation(ExecutionImpl.java:597)
at org.jbpm.pvm.internal.model.ExecutionImpl.start(ExecutionImpl.java:201)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd.execute(StartProcessInstanceInLatestCmd.java:64)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd.execute(StartProcessInstanceInLatestCmd.java:37)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.startProcessInstanceByKey(ExecutionServiceImpl.java:66)
at Test.startUpJBPM(Test.java:40)
at Test.main(Test.java:28)
Caused by: javax.script.ScriptException: Cannot find property TestCon
at org.jbpm.pvm.internal.script.JuelScriptEngine.evalExpr(JuelScriptEngine.java:180)
at org.jbpm.pvm.internal.script.JuelScriptEngine.eval(JuelScriptEngine.java:64)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:84)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:114)
... 17 more
Caused by: javax.el.PropertyNotFoundException: Cannot find property TestCon
at de.odysseus.el.util.SimpleResolver.get(SimpleResolver.java:106)
at de.odysseus.el.util.SimpleResolver.getValue(SimpleResolver.java:126)
at de.odysseus.el.tree.impl.ast.AstIdentifier.eval(AstIdentifier.java:69)
at de.odysseus.el.tree.impl.ast.AstEval.eval(AstEval.java:42)
at de.odysseus.el.tree.impl.ast.AstNode.getValue(AstNode.java:29)
at de.odysseus.el.TreeValueExpression.getValue(TreeValueExpression.java:120)
at org.jbpm.pvm.internal.script.JuelScriptEngine.evalExpr(JuelScriptEngine.java:176)
... 20 more
Exception in thread "main" org.jbpm.api.JbpmException: script evaluation error: Cannot find property TestCon
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:118)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:106)
at org.jbpm.pvm.internal.script.ScriptManager.evaluateExpression(ScriptManager.java:78)
at org.jbpm.jpdl.internal.activity.JavaActivity.perform(JavaActivity.java:68)
at org.jbpm.jpdl.internal.activity.JpdlAutomaticActivity.execute(JpdlAutomaticActivity.java:15)
at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperationSync(ExecutionImpl.java:637)
at org.jbpm.pvm.internal.model.ExecutionImpl.performAtomicOperation(ExecutionImpl.java:597)
at org.jbpm.pvm.internal.model.ExecutionImpl.start(ExecutionImpl.java:201)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd.execute(StartProcessInstanceInLatestCmd.java:64)
at org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd.execute(StartProcessInstanceInLatestCmd.java:37)
at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:54)
at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.startProcessInstanceByKey(ExecutionServiceImpl.java:66)
at Test.startUpJBPM(Test.java:40)
at Test.main(Test.java:28)
Caused by: javax.script.ScriptException: Cannot find property TestCon
at org.jbpm.pvm.internal.script.JuelScriptEngine.evalExpr(JuelScriptEngine.java:180)
at org.jbpm.pvm.internal.script.JuelScriptEngine.eval(JuelScriptEngine.java:64)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:84)
at org.jbpm.pvm.internal.script.ScriptManager.evaluate(ScriptManager.java:114)
... 17 more
Caused by: javax.el.PropertyNotFoundException: Cannot find property TestCon
at de.odysseus.el.util.SimpleResolver.get(SimpleResolver.java:106)
at de.odysseus.el.util.SimpleResolver.getValue(SimpleResolver.java:126)
at de.odysseus.el.tree.impl.ast.AstIdentifier.eval(AstIdentifier.java:69)
at de.odysseus.el.tree.impl.ast.AstEval.eval(AstEval.java:42)
at de.odysseus.el.tree.impl.ast.AstNode.getValue(AstNode.java:29)
at de.odysseus.el.TreeValueExpression.getValue(TreeValueExpression.java:120)
at org.jbpm.pvm.internal.script.JuelScriptEngine.evalExpr(JuelScriptEngine.java:176)
... 20 more
Thanks again for your help.