Wednesday 11 November 2009

Runtime bean wiring

Sproing provides an easy method of wiring an object into Spring at runtime when that object hasn't been created by Spring but needs access to Spring beans.

The SpringWirer class provides a static method that, given an object, will wire it into the existing application context and set the spring beans needed

public class Jedi {
private Force force;

public Jedi() {
// wire this object up
SpringWirer.wireBean(this);
force.push();
}

// set the Force spring bean
public void setForce(Force force) {
this.force = force;
}

}

In this example, the Force object can be accessed because it is a bean defined in Spring. At runtime, the SpringWirer.wireBean(this) call will wire the object into Spring, setting the Force object using the setter method

Sproing version 0.3.1alpha is available now from Sith Open Source

No comments: