jBeanBox第一版终于完成了,已更新到项目目录https://sourceforge.net/projects/jbeanbox/ 下,有兴趣的可以看一看。
这个项目的主要特点:
1)简单,只用一个Java文件实现了IOC/AOP功能,源码不到350行,由此可见实现IOC/AOP实际上很简单。
2) 用Java类代替XML作为配置文件,Java作为配置文件的主要优点是IDE支持类名检查、重构。其实这也是这个项目如此小的原因,因为不用考虑读取和翻译XML文件的问题。
3) 支持所有注入方式如构造器注入、工厂注入等; AOP功能简化,只支持Around方法和切点的正则表达式,但是已能应付大多场合。
4)本项目以功能单一、源码精简为目的,功能仅限于IOC/AOP。 事务支持、DAO支持等业务功能不考虑扩充进来。
目前项目已完成,进入排错阶段,欢迎大家来挑错和试用,谢谢!(Email: Yong9981@gmail.com ) 因为发布在sourceForge,是英文介绍,就对付着看吧。
本贴的附件和网站上的是一样的,打了一个war包,可以直接导入到Eclipse,其中用到了asm-x.x.x.jar和cglib-x.x.jar两个第三方库也打进包了。
jBeanBox1.0.1 is a micro scale(1 file) but full functional IOC & AOP tool, it has no XML files(Use "BeanBox" java classes as configuration), no annotations. 1 single Java class ~350 lines source code do all the IOC/AOP job like Spring framework IOC/AOP core did.
jBeanBox is an open source project follows BSD license, project address: https://sourceforge.net/projects/jbeanbox/
(Note: 2 jar files asm-x.x.x.jar and cglib-x.x.jar are still needed for this project, it's used for create proxy beans similar like Spring did.)
Why jBeanBox?
Some other IOC/AOP frameworks problem:
1) Spring, HiveMind and other IOC/AOP tools use XML as configuration file: XML does not support class name spelling check & IDE refactoring, hard to create/change configuration in run-time.
(I noticed from Spring3.0, it started to use a kind Java class to replace XML, but Java mixed up with annotations, looks weird, and it's hard to create/change configuration at run time.)
About Spring, here are some pros & cons: http://www.aksindiblog.com/spring-framework-advantages-disadvantages.html. For my opinion, as an IOC/AOP tool, it’s too fat(more than 700 classes of core functions).
2) Guice and other IOC/AOP tools depend on annotation: write annotation in Java classes is invasion, IOC/AOP tool should better not change Java files.
jBeanBox is a micro IOC/AOP tool, only focus on IOC/AOP. Its source code are very short and easy to understand. It's ideal to mobile device, small projects, and of cause can be used anywhere where a tiny IOC/AOP tool needed.
Key features of jBeanBox:
1) Simple, only 1 short java file do all the IOC/AOP job. No XML files, no annotations, use pure Java classes as configurations, these Java classes be called "BeanBox" (like "Box" class in another project "jWebBox", in that project 1 single Java file did all jobs Tiles did; It seems using "Box-Oriented Programming” can often make project very short). It's easy to learn and to debug, any problem you can solve by yourself after look into the 350 lines source codes.
2) Compare to XML, Java configurations is not easy to read (but still some programmer like Java, otherwise why Spring invented Java configurations?), but the advantage is it can be organized in packages, and UML tool can used to draw class relationship, and most of all, IDE support class name spelling check and refactoring.
3) Bean configurations (BeanBoxes) can be created dynamically, it's easy to modify or create configurations at run-time, testing become simple and quick, testing configurations(if organized in packages) can be reused in production environment.
4) Small size, ideal for immigrate to mobile device.
How to use it:
For convenient, this project be packaged as .war file, you can throw it into Tomcat or Jboss webapps folder, or import into Eclipse as a web project to see the source code, and run "MainTest.java" to see the test result. There are 2 jar files "asm-3.x.x.jar" and "cglib-2.x.jar" packed in the war package but you can replace these 2 jars by downloading from their websites. There are some test classes in this war package, but for a new project, only 1 java file "BeanBox.java" and 2 libs (asm-3.x.x.jar and cglib-2.x.jar) are needed.
Typically a project using jBeanBox, need prepare below files:
1. Your bean or interface classes, advoice classes(AOP), for example:
public interface Iitem {
public void doPrint();
}
public class ItemImpl implements Iitem {
public void doPrint() {
System.out.println("Do print");
};
}
public class Tester {
private Iitem item;
//gette & setter
public void doPrintItem() {
item.doPrint();
}
}
public class LogAdvicor {//This is an advicor sample
private String name;
public Object doAround(Object[] args) {
System.out.println("=====logger " + name + ", Before method: " + args[2] + "=====");
Object o = BeanBox.invoke(args);
System.out.println("=====logger " + name + ", After method: " + args[2] + "=====");
return o;
}
//getter&setter
}
2. Configuration classes (The substitute of XML):
class TesterBox extends BeanBox {
{
this.setClassOrValue(Tester.class);
this.setProperty("item", new BeanBox(ItemImpl.class));
}
}
3. At last, add point-cut and get bean by call getBean() method:
public static void main(String[] args) {
BeanBox.addAdvicor("com.test.\\w*.\\w*", "doPrint\\w*", new BeanBox(LogAdvicor.class).setProperty("name", "Demo"), "doAround");
Tester t = (Tester) new TesterBox().getBean();
t.doPrintItem();
}
The result:
=====logger Demo, Before method: public void com.test.anotherTest.Tester.doPrintItem()=====
=====logger Demo, Before method: public void com.test.anotherTest.ItemImpl.doPrint()=====
Do print
=====logger Demo, After method: public void com.test.anotherTest.ItemImpl.doPrint()=====
=====logger Demo, After method: public void com.test.anotherTest.Tester.doPrintItem()=====
More usage like Construction injection, Static Factory injection & Bean Factory injection can see test demo in project test folder.
分享到:
相关推荐
jBeanBox项目的定位:需要一个功能较全的IOC/AOP工具,但是又不想引入臃肿的Spring。 其它IOC/AOP工具的问题: Spring: 源码臃肿,Java方式的配置不灵活, 非单例模式时性能差。 Guice: 源码臃肿(200多个类),手工...
该项目为全栈Java开发,采用Nutz框架实现Mvc/Ioc/Aop/Dao/Json一体化设计,源码包含2307个文件,涵盖1742个Java源文件、208个man文档、143个png图片、47个jpg图片、22个js脚本、21个psd设计文件、16个xml文件、13个...
该项目是基于Java语言的jBeanBox设计源码,是一个功能丰富而结构紧凑的微形IOC/AOP工具。该工具集包含241个文件,涵盖225个Java源文件、7个批处理文件、4个Markdown文件、2个XML文件、1个Git忽略文件、1个文本文件和...
在Spring框架中,IOC(Inversion of Control,控制反转)和AOP(Aspect-Oriented Programming,面向切面编程)是两个核心的概念,它们极大地提高了软件开发的灵活性和可维护性。 **IOC(控制反转)**是Spring的核心...
jBeanBox项目的定位:需要一个功能较全的IOC/AOP工具,但是又不想引入臃肿的Spring。 其它IOC/AOP工具的问题: Spring: 源码臃肿,Java方式的配置不灵活, 非单例模式时性能差。 Guice: 源码臃肿(200多个类),手工...
基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)...
通过这种方式,我们可以在不修改目标类代码的情况下,添加额外的功能,实现了与Spring AOP类似的效果。 总结来说,模拟Spring的IoC和AOP主要是通过注解来管理和控制对象的生命周期及行为。虽然这种模拟简化了Spring...
在这个“手写简单实现ioc、aop事务demo”中,我们将探讨如何通过工厂模式和动态代理来实现这些概念。 首先,让我们了解IOC的核心思想。在传统的编程中,对象创建和管理的控制权在程序员手中,而IOC则是将这种控制权...
虽然描述部分为空,但我们可以根据标题推测,这篇文章可能讲述了一个实际的案例或项目,其中作者使用IoC和AOP技术对现有的SOA应用进行了改造,提高了代码的解耦度和模块化,使得系统更易于扩展和维护。博文链接可能...
这个名为“GreeFramOfficial”的压缩包文件,很可能是提供了一个基于C#实现的IOC和AOP框架,供开发者学习和使用。 IOC(Inversion of Control)的核心思想是将对象的创建和管理交给一个容器来处理,而不是由对象...
力求获得一种简洁实用的方法实现IOC和AOP相结合的使用方式。 查阅了多个技术资料。经过多次测试,基本达到目的。 IOC使用微软的 Microsoft.Practices.Unity,AOP 使用微软企业库的 Microsoft.Practices.Enterprise...
Unity是Microsoft推出的一款轻量级、可扩展的依赖注入(DI)容器,它在.NET开发中广泛用于实现Inversion of Control(IoC)设计模式。IoC是一种编程范式,其核心思想是将对象的创建和管理从应用程序的业务逻辑中分离...
Spring 框架是Java开发中的核心框架,它主要由两个关键部分组成:IOC(Inversion of Control,控制反转)和AOP(Aspect Oriented Programming,面向切面编程)。这两个概念是Spring框架的核心特性,极大地简化了企业...
Spring框架是Java开发中不可或缺的一部分,它通过提供两种核心特性——控制反转(IoC)和面向切面编程(AOP)来简化应用的构建。理解并掌握这两种技术对于任何Java开发者来说都至关重要。 **控制反转(IoC)**,也...
Spring框架是Java开发中不可或缺的一部分,它以其强大的依赖注入(IOC)和面向切面编程(AOP)功能而闻名。本项目"spring ioc和aop讲解项目demo"旨在通过实际操作来帮助开发者深入理解这两个核心概念。 首先,让...
Spring框架是Java开发中不可或缺的一部分,它通过引入依赖注入(IOC)和面向切面编程(AOP)的概念,极大地简化了应用程序的构建和管理。在本文中,我们将深入探讨Spring的IOC容器和AOP的核心概念,以及如何进行相关...
标题:“手写实现IoC和AOP开源架构源码2021.pdf”隐含了两个核心概念:IoC(控制反转)和AOP(面向切面编程)。这两个概念是现代软件设计和开发中重要的设计原则和模式,尤其在企业级应用开发中尤为重要。 描述:...
在Java开发领域,IoC(Inversion of Control)和AOP(Aspect-Oriented Programming)是两个非常...在实际项目中,我们通常会结合成熟的框架,如Spring,来利用其内置的IoC和AOP功能,以提高开发效率和系统的稳定性。
Spring框架是Java开发中不可或缺的一部分,它以模块化的方式提供了许多功能,如依赖注入(IOC)、面向切面编程(AOP)以及Model-View-Controller(MVC)架构模式。在本实例中,我们将深入探讨这三个核心概念以及它们...