---
title: "在jbpm3中使用Ioc"
author: "hongsoft"
date: "2005-02-21T15:48:00Z"
tags: []
slug: "jbpm3-ioc"
draft: false
lastmod: "2005-02-21T15:48:00Z"
id: 287489
url: "https://hongsoft.iteye.com/blog/287489"
---

在jbpm3中,采用反射实现了从配置文件中构造一个新的对象的功能,  
使用方法如下:  
   String configuration =  
      "&lt;s&gt;hello&lt;/s&gt;" +  
      "&lt;stringConstructor&gt;" +  
      "  i want yoghurt" +  
      "&lt;/stringConstructor&gt;" +  
      "&lt;structuredElement&gt;" +  
      " &lt;surfboard length=\\"270\\" /&gt;" +  
      " &lt;mast length=\\"475\\" /&gt;" +  
      " &lt;boom length=\\"160\\" /&gt;" +  
      " &lt;sail size=\\"5.7\\" /&gt;" +  
      "&lt;/structuredElement&gt;" +  
      "&lt;memberWithoutSetter&gt;hello&lt;/memberWithoutSetter&gt;";  
     
    Mix mix = (Mix) beanInstantiator.instantiate(Mix.class, configuration);  
     
    assertEquals( "hello", mix.s );  
它的实现方法很简单,就是使用java.lang.reflect.\*包,构造对象,然后根据解析的文件  
为对象的属性赋值

其实,我们把它的实现稍做扩展,就可以实现我们自己的ioc:  
Mix mix=(Mix)MyIoc.getbean("theMix");  
和  
Mix mix = (Mix) beanInstantiator.instantiate(Mix.class, configuration);  
比较,显得更简单一些,呵呵.