T
- the type of bean to runpublic abstract class AbstractCommandLineRunner<T>
extends java.lang.Object
The general idea of this launcher concept is to provide
a way to define context config location, bean name for execution
handling, options and a arguments. Possible examples are:
contextConfig contextConfig,childContextConfig beanIdentifier contextConfig beanIdentifier <arguments> contextConfig <options> beanIdentifier contextConfig <options> beanIdentifier <arguments> <options> contextConfig <options> beanIdentifier <arguments>
Constructor and Description |
---|
AbstractCommandLineRunner() |
Modifier and Type | Method and Description |
---|---|
protected void |
doMain(java.lang.String[] args)
Main method visible to sub-classes.
|
void |
exit(int status)
Exit method wrapping handling through
SystemExiter . |
protected org.springframework.context.ConfigurableApplicationContext |
getApplicationContext(java.lang.String configLocation)
Gets the Application Context.
|
protected org.springframework.context.ConfigurableApplicationContext |
getChildApplicationContext(java.lang.String configLocation,
org.springframework.context.ConfigurableApplicationContext parent)
Gets the Application Context.
|
protected java.lang.String |
getChildContextConfigPath(java.lang.String path)
Allows subclass to modify parsed context configuration path.
|
protected java.lang.String |
getContextConfigPath(java.lang.String path)
Allows subclass to modify parsed context configuration path.
|
protected abstract java.lang.String |
getDefaultBeanIdentifier()
Gets a default bean id which is used to resolve
the instance from an Application Context.
|
static java.lang.String |
getErrorMessage()
Gets the static error message set for
this class.
|
protected java.util.List<java.lang.String> |
getValidOpts()
Gets the list of valid option arguments.
|
protected abstract ExitStatus |
handleBeanRun(T bean,
java.lang.String[] parameters,
java.util.Set<java.lang.String> opts)
Handles the execution of a bean after Application Context(s) has
been initialized.
|
static void |
presetSystemExiter(SystemExiter systemExiter)
Sets the
SystemExiter . |
protected int |
start(java.lang.String configLocation,
java.lang.String masterIdentifier,
java.lang.String childConfigLocation,
java.lang.String[] parameters,
java.util.Set<java.lang.String> opts)
Builds the Application Context(s) and handles 'execution'
of a bean.
|
public static java.lang.String getErrorMessage()
public static void presetSystemExiter(SystemExiter systemExiter)
SystemExiter
. Useful
for testing.systemExiter
- the system exiterprotected abstract ExitStatus handleBeanRun(T bean, java.lang.String[] parameters, java.util.Set<java.lang.String> opts)
It is implementors responsibility to decide what to do with the given bean since this class only knows the typed bean instance.
bean
- the bean instanceparameters
- the parametersopts
- the optionsprotected abstract java.lang.String getDefaultBeanIdentifier()
protected java.util.List<java.lang.String> getValidOpts()
When overriding valid options make sure that options doesn't match anything else planned to be used in a command line. i.e. usually it's advised to prefix options with '-' character.
protected java.lang.String getContextConfigPath(java.lang.String path)
Default implementation just returns the given without modifying it.
path
- the parsed config pathprotected java.lang.String getChildContextConfigPath(java.lang.String path)
Default implementation just returns the given without modifying it.
path
- the parsed config pathprotected int start(java.lang.String configLocation, java.lang.String masterIdentifier, java.lang.String childConfigLocation, java.lang.String[] parameters, java.util.Set<java.lang.String> opts)
configLocation
- the main context config locationmasterIdentifier
- the bean identifierchildConfigLocation
- the child context config locationparameters
- the parametersopts
- the optionsprotected org.springframework.context.ConfigurableApplicationContext getApplicationContext(java.lang.String configLocation)
configLocation
- the context config locationprotected org.springframework.context.ConfigurableApplicationContext getChildApplicationContext(java.lang.String configLocation, org.springframework.context.ConfigurableApplicationContext parent)
configLocation
- the context config locationparent
- the parent contextpublic void exit(int status)
SystemExiter
. This method mostly
exist order to not do a real exit on
a unit tests.status
- the exit codeprotected void doMain(java.lang.String[] args)
args
- the Arguments