Over a million developers have joined DZone.

Butterfly DI Container 2.4.0

DZone's Guide to

Butterfly DI Container 2.4.0

· ·
Free Resource

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.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}