Package io.dropwizard.core
Class Application<T extends Configuration>
- java.lang.Object
-
- io.dropwizard.core.Application<T>
-
- Type Parameters:
T
- the type of configuration class for this application
public abstract class Application<T extends Configuration> extends Object
The base class for Dropwizard applications. Because the default constructor will be inherited by all subclasses, {BootstrapLogging.bootstrap()} will always be invoked. The log level used during the bootstrap process can be configured by {Application} subclasses by overriding {#bootstrapLogLevel}.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Application()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addDefaultCommands(Bootstrap<T> bootstrap)
Called byrun(String...)
to add the standard "server" and "check" commandsprotected void
bootstrapLogging()
protected ch.qos.logback.classic.Level
bootstrapLogLevel()
The log level at which to bootstrap logging on application startup.Class<T>
getConfigurationClass()
Returns theClass
of the configuration class type parameter.String
getName()
Returns the name of the application.void
initialize(Bootstrap<T> bootstrap)
Initializes the application bootstrap.protected void
onFatalError(Throwable t)
Called byrun(String...)
to indicate there was a fatal error running the requested command.void
run(String... arguments)
Parses command-line arguments and runs the application.abstract void
run(T configuration, Environment environment)
When the application runs, this is called after theConfiguredBundle
s are run.
-
-
-
Method Detail
-
bootstrapLogLevel
protected ch.qos.logback.classic.Level bootstrapLogLevel()
The log level at which to bootstrap logging on application startup.
-
bootstrapLogging
protected void bootstrapLogging()
-
getConfigurationClass
public Class<T> getConfigurationClass()
Returns theClass
of the configuration class type parameter.- Returns:
- the configuration class
- See Also:
Generics.getTypeParameter(Class, Class)
-
getName
public String getName()
Returns the name of the application.- Returns:
- the application's name
-
initialize
public void initialize(Bootstrap<T> bootstrap)
Initializes the application bootstrap.- Parameters:
bootstrap
- the application bootstrap
-
run
public abstract void run(T configuration, Environment environment) throws Exception
When the application runs, this is called after theConfiguredBundle
s are run. Override it to add providers, resources, etc. for your application.- Parameters:
configuration
- the parsedConfiguration
objectenvironment
- the application'sEnvironment
- Throws:
Exception
- if something goes wrong
-
run
public void run(String... arguments) throws Exception
Parses command-line arguments and runs the application. Call this method from apublic static void main
entry point in your application.- Parameters:
arguments
- the command-line arguments- Throws:
Exception
- if something goes wrong
-
addDefaultCommands
protected void addDefaultCommands(Bootstrap<T> bootstrap)
Called byrun(String...)
to add the standard "server" and "check" commands- Parameters:
bootstrap
- the bootstrap instance
-
onFatalError
protected void onFatalError(Throwable t)
Called byrun(String...)
to indicate there was a fatal error running the requested command. The default implementation callsSystem.exit(int)
with a non-zero status code to terminate the application.- Parameters:
t
- TheThrowable
instance which caused the command to fail.- Since:
- 2.0
-
-