Class ContextMainClass

java.lang.Object
org.dellroad.stuff.main.MainClass
org.dellroad.stuff.main.ContextMainClass

public abstract class ContextMainClass extends MainClass
Support superclass for MainClass implementations that wish to execute with an associated Spring application context.
  • Field Details

  • Constructor Details

    • ContextMainClass

      public ContextMainClass()
  • Method Details

    • getContextLocation

      protected String getContextLocation()
      Get the classpath location of this instance's associated XML application context. The returned string will resolved on the classpath relative to this instance's class.

      The implementation in ContextMainClass returns getClass().getSimpleName() + ".xml", which will locate an XML file in the same package and with the same name.

      Returns:
      application context XML file location
    • autowire

      protected void autowire()
      Autowire this instance using its associated application context. This may be invoked by runInContext(java.lang.String[]) to autowire this bean using its associated context.

      For this to work, the application context must have autowiring enabled, e.g., via <context:annotation-config/>.

    • run

      public int run(String[] args) throws Exception
      Description copied from class: MainClass
      Subclass main implementation. This method is free to throw exceptions; these will be displayed on standard error and converted into non-zero exit values.
      Specified by:
      run in class MainClass
      Parameters:
      args - command line arguments
      Returns:
      process exit value
      Throws:
      Exception - if an error occurs; will result in the process exiting with an exit value of one
    • runInContext

      protected abstract int runInContext(String[] args) throws Exception
      Execute the main method. The application context will be open when this method is invoked.
      Parameters:
      args - command line arguments
      Returns:
      process exit value
      Throws:
      Exception - if an error occurs; will result in the process exiting with an exit value of one