这是一个微形开源项目,目标是使用单个Java类实现基本的IOC和AOP功能,有兴趣参加的朋友可以跟贴,贡献者将列入作者名单,谢谢!
项目的目的是取消XML配置文件而用纯Java类代替,只等价实现Spring中最基本的IOC和AOP功能以避免臃肿且满足功能单一原则。用尽可能短小、易读的源码(最好是单个Java类) 实现,基本思路可参见我的另一贴"JSP页面布局工具jWebBox升级到2.0版" http://www.iteye.com/topic/1143195, 利用Java类本身的特点来实现免学习、高灵活性、高扩展性、支持UML、IDE类名检查和代码提示的优点。 项目采用BSD协议,源码将暂时发布在jWebBox项目的jBeanBox目录下。
以下是对此项目的描述:
jBeanBox is a lightweight IOC & AOP tool, playing the same role like Spring IOC & AOP, but it's pure Object-Oriented designed, no XML configuration file, it's simple(only 1 java class) and easy to use, it can be used to manage all beans in project or only for few Beans.
jBeanBox is an open source software follows BSD license.
Key features about jBeanBox
1)Use Java classes, not XML file to present Bean Configurations, the Java class be called "BeanBox".
2)As use Java class, IDE can help to check class name spelling mistake, UML tool can be used to draw bean relationship graph.
2)No conflict with other bean containers like Spring/pico..., it can be used to manage all beans in project or only few Beans in project.
3)No XML file needed, no 3rd party jar library needed.
4)Bean configurations (BeanBox classes) are created dynamically, it's easy to modify or create configurations at run-time. For example, change bean create method from singleton to prototype, add or cancel AOP cut points for beans at run-time.
5)Only 1 file "BeanBox.java" is necessary, no .jar file can be found in this project because it's recommended to copy "BeanBox.java" into your source code folder, so you can read and modify source code easily.
6)Currently this tool only implemented IOC and AOP function, IOC support 3 injection methods: construction, setter and interface injection.
How to use it:
Copy "BeanBox.java" into your source code folder.
Typically a project using jBeanBox, need prepare below files:
1. Your bean or interface classes, for example:
public class OrderItem {
public void printOrderItem() {
System.out.print("Irder item 1");
}
}
public class Order {
private OrderItem orderitem;
public OrderItem getOrderitem() {
return orderitem;
}
public void setOrderitem(OrderItem orderitem) {
this.orderitem = orderitem;
}
}
public class Customer{
private Order order;
public Order getOrder() {
return order
}
public void setOrder(Order order) {
this.order = order;
}
......
}
2. Configration classes (BeanBox classes):
public CustomerBeanBox extends BeanBox(){
{
this.setBean(Customer.class);
//this.setBeanType(Box.SINGLETON) //default is SingleTon
this.addAOPBefore(xxxAspecBeanBox.class, "doBefore"); //Add AOP cut point
this.setProperty("order", new BeanBox(Order.class).setProperty("orderitem",OrderItem.class));
}
}
At last, use below methods to finish the bean assembly (injection & AOP):
public static void main(String [] args)
{
BeanBox.addAOP(xxxAspectBeanBox.class,"execute(* com.deom.service.*"); //Global AOP setting
Order order1=CustomerBeanBox.getBean();
//or
Order order2=BeanBox.getBean(Order.class); //In this way, BeanBox class naming rule should be "Classname"+"BeanBox"
}