An Oddjob Property in Spring

Here’s my previous password passed to Spring example run from Oddjob:

Password PromptRun as a GUI, Oddjob provides a simple form for entering properties including a password prompt.

Here’s the Oddjob configuration:

<oddjob>
  <job>
    <sequential>
      <jobs>
        <input>
          <requests>
            <input-password prompt="Password" property="jdbc.password" />
          </requests>
        </input>
        <spring:job beanName="myQuery" xmlns:spring="oddjob:spring">
          <resources>
            <list>
              <values>
                <value value="rob/MyQuery.xml" />
              </values>
            </list>
          </resources>
        </spring:job>
      </jobs>
    </sequential>
  </job>
</oddjob>

The Spring configuration remains unchanged from my previous post, but I include it again here for your convenience:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:property-placeholder location="classpath:jdbc.properties" />

  <bean id="myQuery" class="rob.MyQuery">
    <property name="dataSource" ref="dataSource" />
  </bean>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
  </bean>

</beans>

The password prompt sets the property jdbc.password within Oddjob and my new SpringJob automatically makes every property defined in Oddjob available in Spring.

SpringJob can be given the name of any Runnable defined within Spring and it will run it. Any exceptions will be reflected in the state of SpringJob, and this can be used to trigger another job such as an email, or it can be used in a retry timer.

Here it is having run successfully.

Spring Job CompletedThe Oddjob configuration can be run directly from the console. The password prompt now changes to use the console:

Spring Job Console View

And that’s a very quick look at an Oddjob property in Spring.

The Oddjob Spring jobs can be found on Sourceforge here. They require Oddjob 1.2 to run, it is still in development but a reasonably stable snapshot can be found here.

Comments are closed.