Monday, 19 March 2012

Creating a Spring Application

Creating a standalone (ie non-web) application can seem a little confusing to some. Sproing makes this easy by extending a Sproing class and implementing a method, and that's it!

All you need do is have your main (the class with the main() method that starts the application) extend ApplicationWirer and implement the getPaths() method that returns the path(s) to your application context xml files. Then a single call to the wire() method does the rest
public class Main extends ApplicationWirer {
  public static void main(String[] args) {
    Main main = new Main();
  public String[] getPaths() {
    return new String[] {"applicationContext.xml"};

This code will start your application and load the applicationContext.xml file into spring with all the spring beans defined. Easy!

Sproing version 0.3.1alpha is available now from Sith Open Source

No comments:

Post a Comment