Package io.dropwizard
Class Application<T extends Configuration>
- java.lang.Object
-
- io.dropwizard.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 protectedApplication()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddDefaultCommands(Bootstrap<T> bootstrap)Called byrun(String...)to add the standard "server" and "check" commandsprotected voidbootstrapLogging()protected ch.qos.logback.classic.LevelbootstrapLogLevel()The log level at which to bootstrap logging on application startup.Class<T>getConfigurationClass()Returns theClassof the configuration class type parameter.StringgetName()Returns the name of the application.voidinitialize(Bootstrap<T> bootstrap)Initializes the application bootstrap.protected voidonFatalError()Deprecated.Use #onFatalError(Throwable) instead.protected voidonFatalError(Throwable t)Called byrun(String...)to indicate there was a fatal error running the requested command.voidrun(String... arguments)Parses command-line arguments and runs the application.abstract voidrun(T configuration, Environment environment)When the application runs, this is called after theConfiguredBundles 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 theClassof 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 theConfiguredBundles are run. Override it to add providers, resources, etc. for your application.- Parameters:
configuration- the parsedConfigurationobjectenvironment- 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 mainentry 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- TheThrowableinstance which caused the command to fail.- Since:
- 2.0
-
onFatalError
@Deprecated protected void onFatalError()
Deprecated.Use #onFatalError(Throwable) instead.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.
-
-