Package org.dellroad.stuff.main
Class ContextMainClass
java.lang.Object
org.dellroad.stuff.main.MainClass
org.dellroad.stuff.main.ContextMainClass
Support superclass for
MainClass implementations that wish to execute
with an associated Spring application context.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidautowire()Autowire this instance using its associated application context.protected StringGet the classpath location of this instance's associated XML application context.intSubclass main implementation.protected abstract intrunInContext(String[] args) Execute the main method.Methods inherited from class org.dellroad.stuff.main.MainClass
doMain, errout, parsePropertyFlags, usageError, usageMessage
-
Field Details
-
context
-
-
Constructor Details
-
ContextMainClass
public ContextMainClass()
-
-
Method Details
-
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
ContextMainClassreturnsgetClass().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 byrunInContext(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
Description copied from class:MainClassSubclass main implementation. This method is free to throw exceptions; these will be displayed on standard error and converted into non-zero exit values. -
runInContext
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
-