public class CommandLineHelper extends Object implements AutoCloseable
Example:
public static void main(String[] args) { try (CommandLineHelper clh = new CommandLineHelper()) { clh.contextRegister(MyConfig.class); clh.runApplication(new MyJob()); } }
Modifier and Type | Field and Description |
---|---|
static String |
SPRING_CONFIG
Spring Java Config Class Name.
|
static String |
SPRING_PROPERTIES
PropertySource - Spring Properties.
|
Constructor and Description |
---|
CommandLineHelper()
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
contextRegister(Class<?>... annotatedConfigurationClasses)
Configure the application context with the specified java configuration class.
|
void |
contextScan(String... basePackages)
Scan the specified packages for Spring configuration.
|
void |
exit()
Shutdown and cleanly exit the program / VM.
|
<R> R |
runApplication(Callable<R> application)
Start the specified application and wait until it is
finished before returning.
|
void |
runApplication(Runnable application)
Start the specified application and wait until it is
finished before returning.
|
<R> R |
runApplicationCallableClass(Class<? extends Callable<R>> applicationClass)
Start the specified application and wait until it is
finished before returning.
|
void |
runApplicationRunnableClass(Class<? extends Runnable> applicationClass)
Start the specified application and wait until it is
finished before returning.
|
<R> Future<R> |
startApplication(Callable<R> application)
Start the specified application.
|
Future<?> |
startApplication(Runnable application)
Start the specified application.
|
<R> Future<R> |
startApplicationCallableClass(Class<? extends Callable<R>> applicationClass)
Start the specified application.
|
void |
startApplicationContext()
Start the ApplicationContext.
|
Future<?> |
startApplicationRunnableClass(Class<? extends Runnable> applicationClass)
Start the specified application.
|
public static final String SPRING_CONFIG
public static final String SPRING_PROPERTIES
public void close()
close
in interface AutoCloseable
public void contextRegister(Class<?>... annotatedConfigurationClasses)
annotatedConfigurationClasses
- the configuration classes.AnnotationConfigApplicationContext.register(Class[])
public void contextScan(String... basePackages)
basePackages
- the base packages.AnnotationConfigApplicationContext.scan(String...)
public void exit()
@Nullable public <R> R runApplication(@Nonnull Callable<R> application)
The application context will be available
when the call
method is called.
R
- the return type.application
- the application to run.public void runApplication(@Nonnull Runnable application)
The application context will be available
when the run
method is called.
application
- the application to run.@Nullable public <R> R runApplicationCallableClass(@Nonnull Class<? extends Callable<R>> applicationClass)
The application context will be available when the class is instantiated.
R
- the return type.applicationClass
- the application to run.public void runApplicationRunnableClass(@Nonnull Class<? extends Runnable> applicationClass)
The application context will be available when the class is instantiated.
applicationClass
- the application to run.public <R> Future<R> startApplication(@Nonnull Callable<R> application)
The application context will be available
when the call
method is called.
R
- the return type.application
- the application to run.public Future<?> startApplication(@Nonnull Runnable application)
The application context will be available
when the run
method is called.
application
- the application to run.public <R> Future<R> startApplicationCallableClass(@Nonnull Class<? extends Callable<R>> applicationClass)
The application context will be available when the class is instantiated.
R
- the return type.applicationClass
- the application to run.public void startApplicationContext()
public Future<?> startApplicationRunnableClass(@Nonnull Class<? extends Runnable> applicationClass)
The application context will be available when the class is instantiated.
applicationClass
- the application to run. Must have a no-arg constructor.