Oddjob With Spring

Spring is great for creating flexible applications by assembling loosely coupled components using XML. Here’s a simple Spring configuration file:

<beans xmlns="http://www.springframework.org/schema/beans"


  <bean id="hello" class="example.HelloWorldBean" />


Except that now you have to go back to your context assisted IDE and write some Java to launch it!

public static void main(String... args) {

	ConfigurableApplicationContext ctx = 
			new ClassPathXmlApplicationContext(

	Runnable hello = ctx.getBean("hello", Runnable.class);



Wouldn’t it be great if you could have some more XML that launched your Spring App instead of this pesky Java code! And how cool would it be if that XML were in a completely different format from that which Spring uses, such as this:

<oddjob id="this">
        <spring:beans id="spring" xmlns:spring="oddjob:spring">
                <file file="${this.dir}/classes" />
                <value value="${spring.class.classLoader}" />
            <value value="classpath:config/spring/Simple.xml" />
        <run job="${spring/hello}" />

Not convinced? Really? OK – I agree, more XML is the last thing you want. It might, however, be worth it if your Spring App is on a remote server. Launching it from Oddjob can give you a quick (but crude) view into it, like this:

Remote Spring Running In OddjobHere we see our HelloWorldBean provided by Spring but run by Oddjob. We can see that it has run and we can see the value of its only property, the runCount, which is how many times it has run.

Oddjob uses JMX to provide the client/server bit, so it was simply a case of launching Oddjob with remote JMX enabled, like this:

java -Dcom.sun.management.jmxremote.port=13013
-jar c:\Users\rob\java\oddjob\run-oddjob.jar -f Server.oj.xml

And then running the client Oddjob with this configuration:

    <jmx:client connection="localhost:13013" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx" />

The Spring Oddball (An Oddball is an Oddjob plugin) is fairly experimental at the moment. The latest snapshot can be downloaded from SourceForge here. The source code is on GitHub here.

All that remains now is for me to ask – Does Oddjob look like a good enough reason for more XML with Spring?

Comments are closed.