Over a million developers have joined DZone.

Why I Wrote Yet Another Java Bean Framework

DZone's Guide to

Why I Wrote Yet Another Java Bean Framework

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

With so many Java Bean XML and dependency injection frameworks out there – did I really need to write another? Am I suffering from some terrible ‘Not Invented Here’ syndrome? In this post I’m hoping to persuade myself that I’m not, and hopefully I can persuade you that it might be worth a look too.

It all came down to Drag and Drop. I wrote my own framework because I couldn’t find another that allowed beans to be Cut, Pasted and Configured in place – while running – no restart required!

Here it is working between two server processes, scroll quickly for that Flip Book animation effect!

Oddjob Drag and Drop 1

Oddjob Drag and Drop 2

Oddjob Drag and Drop 3

What’s going on? – I’m dragging the XML configuration for a bean from one server process to another. Here are those server processes:

Oddjob Drag and Drop Servers

Now I’m going to drag that job straight into this post…

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<echo id="echo-job"><![CDATA[Hello from ${server.name}]]></echo>

 …and no I didn’t cheat!

Here is that server drag and drop again, except in code:

public class CutAndPaste {
    public static void main(String... args) throws Exception {
        Oddjob oddjob = new Oddjob();
        oddjob.setConfiguration(new XMLConfiguration(new File("client.xml")));
        OddjobLookup lookup = new OddjobLookup(oddjob);
        DragPoint drag1 = lookup.lookup("client1/server-jobs", ConfigurationOwner.class
        String copy = drag1.copy();
        DragPoint drag2 = lookup.lookup("client2/server-jobs", ConfigurationOwner.class
        drag2.paste(0, copy);
        Runnable job = lookup.lookup("client2/server-jobs/echo-job", Runnable.class);

I also run the job in its new location – just for good measure.

Now many of you will be saying ‘Why would I want anyone dragging around my applications configuration!’, and yes, in production this is quite dangerous and most of the time you probably do want all your beans and their dependencies locked down.

But sometimes it might be really useful to have a bit of flexibility with your remote components configuration, and for those sometimes I wrote a cut and paste Java Bean XML based dependency injection framework.

Now I’m expecting lots of feedback telling me that XYZ framework will do this already, and I’m looking forward to it, and I don’t mind – because there is another reason I wrote the framework, the main reason… I loved every minute of it!


Source: http://rgordon.co.uk/blog/2012/02/03/why-i-wrote-yet-another-java-bean-framework/

Download Modern Java EE Design Patterns: Building Scalable Architecture for Sustainable Enterprise Development.  Brought to you in partnership with Red Hat


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}