Computers have been my hobby since I was 12. Now I'm a freelance Java developer. Like many other developers I am working on various private projects. Some are open source components (Butterfly Components - DI container, web ui, persistence api, mock test api etc.). Some are the tutorials at Yet others are web projects. I hold a bachelor degree in computer science and a master degree in IT focused on P2P networks. Jakob has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

Butterfly DI Container 2.4.0

  • submit to reddit

Butterfly Container is a Java dependency injection container. It is smaller (~100KB jar), yet more flexible and easier to use than Spring, Pico, and Guice (at least in the developers' opinion). Instead of XML, Butterfly Container is configured using a simple, flexible, Java-like configuration language, or by plugging plain non-annotation, non-reflection Java factories into the container. There are no external dependencies.

In addition to being smaller, Butterfly Container is also much faster than Guice, which again claims to be faster than Spring.

Here are a few examples of the configuration language:

myBean1 = * com.jenkov.MyBean();        /* simple instantiation*/
myBean2 = * com.jenkov.MyBean(myBean1); /* constructor injection*/
myBean3 = * com.jenkov.MyBean(myBean2)
              .setExtraBean(myBean1);   /* constructor + setter injection */

Version 2.4.0 is the stable release of the 2.3.x beta series. It contains much improved error messages during container script parsing, and a few bug fixes related to casting to Java primitives in the scripts.

Version 2.4.0 also pioneers the implementation of the exception enrichment technique described here:

Version 2.4.0 is the third release this year, but not the last. More advanced features are planned for release this year. Features like easy map configuration, internationalization support etc.

We are also currently working on an extended user guide. It is not yet public, but it already a 90 page PDF (A4). Butterfly Container is incredibly flexible, so covering all the possibilities takes up quite a few pages.

Average: 5 (1 vote)
Published at DZone with permission of its author, Jakob Jenkov.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)