Java微容器

Java微容器
1:基于Bean元素定义方式构造
2:提供友好的使用接口
3:扩展性好,支持类型转换器
4:代码结构清晰,可读性好
5:工具极少依赖外部Jar包
6:编译压缩后体积小(170k),不臃肿.
7:提供容器内部原理说明文档
8:提供参考例子代码,包括两种方式,A:直接调用容器,B:XML配置方式
9:100%国人原创轻量级Ioc工具

国内下载: http://pan.baidu.com/share/home?uk=2218126399

 

 这里例举一个属性注入测试代码

1:定义一个Bean

package org.jmin.test.ioc.property;
public class Man {
  private String name;
  private int 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;
  }
}


2: 直接调用容器获取Bean实例

package org.jmin.test.ioc.property;

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 PropertyCase{
 
  public static void test()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("Bean1", Man.class, new InjectionProperty[] {nameProperty, ageProperty});
    Man man = (Man)container.getBean("Bean1");
    if(man!=null){
        if("Chris".equals(man.getName()) && (28== man.getAge())){
           System.out.println("[Container].........属性注入测试成功..........");
         }else{
           throw new Error("[Container]...........属性注入测试失败............");
         }
      }
   }

    //启动测试方法
   public static void main(String[] args)throws Throwable{
     test();
   }
}

 

 3:XML调用方式

<?xml version="1.0"?>
<beans>
 <bean id ="Bean1" class="org.jmin.test.ioc.property.Man">
  <property name="name" value="Chris"/>
  <property name="age"  value="28"/>
 </bean>
</beans>

调用代码

package org.jmin.test.ioc.property;

import org.jmin.ioc.impl.config.BeanContext;

public class PropertyXMLCase{
  public static void test()throws Throwable{
    BeanContext context=new BeanContext("org/jmin/test/ioc/property/pojo.xml");
    Man man = (Man)context.getBean("Bean1");
    if(man!=null){
     if("Chris".equals(man.getName()) && (28== man.getAge())){
        System.out.println("[XML].........属性注入测试成功..........");
      }else{
         throw new Error("[XML]...........属性注入测试失败............");
      }
    }
  }
 
  //启动测试方法
  public static void main(String[] args)throws Throwable{
   test();
  }
}

 更多代码下载地址

国内下载: http://pan.baidu.com/share/home?uk=2218126399

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值