Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Oddjob Property in Spring

DZone's Guide to

An Oddjob Property in Spring

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

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

Password Prompt

Run 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 Completed

The 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.

 

 

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.

Topics:

Published at DZone with permission of Rob Gordon, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}