[jboss-user] [JBoss jBPM] - Re: Integration problem of jBPM 4, Spring and Hibernate
KeithWong123
do-not-reply at jboss.com
Tue Aug 4 07:41:46 EDT 2009
Thank you for your help! However, other problems come out......
Do you have any working example or tutorial recommended to me? I want to learn how to integrate JBPM4, Spring and Hibernate. However, I cannot find any example which can guide me through the whole process.
Now I am facing this problem:
How to call Spring beans from a JBPM4 process? Should I create an 'environment' variable to access Spring bean?
The following is my code:
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.EnvironmentFactory;
| import org.jbpm.pvm.internal.env.SpringContext;
| import org.springframework.beans.BeansException;
| import org.springframework.context.ApplicationContext;
| import org.springframework.context.ApplicationContextAware;
| 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();
| //EnvironmentFactory environmentFactory = new PvmEnvironmentFactory("environment.cfg.xml");
| environment.setContext(new SpringContext(ac)); <=== Not sure how to create and use 'environment'
| }
|
| 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("productManager");
| Product p = new Product();
| p.setSku("04081528");
| p.setQuantity(04);
| p.setSupplierCode("04081528");
| p.setIsMain(0);
| managerProduct.addProduct(p);
| }
| public ProductManager getManagerProduct() {
| return managerProduct;
| }
|
| public void setManagerProduct(ProductManager managerProduct) {
| this.managerProduct = managerProduct;
| }
|
| public void setApplicationContext(ApplicationContext ac)throws BeansException {
| this.ac=ac;
| }
|
|
| }
|
Please help to indicate what is wrong.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4247828#4247828
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4247828
More information about the jboss-user
mailing list