minBox是一款小型的Java Ioc容器,具有以下特点1:基于Bean元素定义方式构造
2:提供友好的使用接口
3:扩展性好,支持类型转换器
4:代码结构清晰,可读性好
5:工具极少依赖外部Jar包
6:编译压缩后体积小(170k),不臃肿.
7:提供容器内部原理说明文档
8:提供参考例子代码,包括两种方式,A:直接调用容器,B:XML配置方式
9:100%原创轻量级Ioc工具地址:http://dl.vmall.com/c0u7lix55w附:
本人是菜鸟一个,最近在学习Ioc技术,突然心血来潮,就尝试写了这么一个小工具,贴在这里只是想向大家
学习请教,绝无炫耀之意(几行代码而已),若惊搅之处,望谅解!

解决方案 »

  1.   

    写ioc不难 难的是写一个spring一样的ioc有空看看lz的代码
      

  2.   

    对于Ioc容器,我的想法是依据某些想法设计出一些接口,类似规范之类的(对菜鸟来说,有点。),
    然后再基于这些提供实现
      

  3.   

    Java Bean
     
    public class Boy {
      private String name;//name
      private int age;//age
      
      public int getAge() {
        return age;
      }
      public void setAge(int age) {
        this.age = age;
      }
      public String getName() {
        return name;
      }
      public void setName(String name) {
        this.name = name;
      }
    }
    1:直接调用容器代码import org.jmin.ioc.BeanContainer;
    import org.jmin.ioc.BeanElementFactory;
    import org.jmin.ioc.BeanParameter;
    import org.jmin.ioc.BeanParameterFactory;
    import org.jmin.ioc.element.InjectionProperty;
    import org.jmin.ioc.impl.BeanContainerImpl;
     
    public class Test{
      public static void main(String[] args) throws Throwable {
        BeanContainer container = new BeanContainerImpl();
        BeanElementFactory beanElementFactory =container.getBeanElementFactory();
        BeanParameterFactory beanParameterFactory=container.getBeanParameterFactory();
        BeanParameter nameParmeter =beanParameterFactory.createStringParameter("Chris");
        BeanParameter ageParmeter =beanParameterFactory.createIntegerParameter(28);
        
        InjectionProperty nameProperty = beanElementFactory.createInjectionProperty("name",nameParmeter);
        InjectionProperty ageProperty = beanElementFactory.createInjectionProperty("age",ageParmeter);
        container.registerClass("boy", Boy.class, new InjectionProperty[] {nameProperty, ageProperty});
        
        Boy boy = (Boy)this.container.getBean("boy");
        if(boy!=null){
           if("Chris".equals(boy.getName()) && (28== boy.getAge())){
           System.out.println("[Container].........属性注入测试成功..........");
          }else{
           throw new Error("[Container]...........属性注入测试失败............");
          }
        }
      }

    2:XML配置方式<?xml version="1.0"?>
    <beans>
     <bean id ="Bean1" class="Boy">
      <property name="name" value="Chris"/>
      <property name="age"   value="28"/>
     </bean>
    </beans>import org.jmin.ioc.impl.config.BeanContext;
    public class Test{
      public static void main(String[] args) throws Throwable {
       BeanContext context=new BeanContext("org/jmin/test/ioc/property/pojo.xml");
       Boy boy = (Boy)this.context.getBean("boy");
       if(boy!=null){
          if("Chris".equals(boy.getName()) && (28== boy.getAge())){
             System.out.println("[XML].........属性注入测试成功..........");
           }else{
             throw new Error("[XML]...........属性注入测试失败............");
           }
         }
       }
    }