Spring beans are weired using the AutowireCapableBeanFactory.AUTOWIRE_BY_NAME strategy, so your object needs to have setter methods with the same names as the beans you want to wire up. You need to create a subclass of ApplicationWirer and implement the getPaths() method to return the paths of the spring application context files you want to wire up
For example:
public class YourAppWirer extends ApplicationWirer {
public String[] getPaths() {
return new String[] {
"classpath:someApplicationContext.xml",
"classpath:applicationContext.xml"};
}
}
To wire up your object, all you need do is create a new instance of your overridden ApplicationWirer class in a constructor on your object, and call the wire() method
For example, using YourAppWirer in the above example:
public class JediMindTrick {
public JediMindTrick() {
new YourAppWirer().wire(this);
}
}
Provided you have defined public setter methods for any spring dependencies your object needs, and called them the same names as described above, spring will inject these at runtime. You can then write your object methods as normal
Sproing version 0.3.1alpha is available now from Sith Open Source
No comments:
Post a Comment