Class Application<T extends Configuration>

java.lang.Object
io.dropwizard.core.Application<T>
Type Parameters:
T - the type of configuration class for this application
Direct Known Subclasses:
HelloWorldApplication

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 Details

    • Application

      protected Application()
  • Method Details

    • 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 the Class of the configuration class type parameter.
      Returns:
      the configuration class
      See Also:
    • 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 the ConfiguredBundles are run. Override it to add providers, resources, etc. for your application.
      Parameters:
      configuration - the parsed Configuration object
      environment - the application's Environment
      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 a public 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 by run(String...) to add the standard "server" and "check" commands
      Parameters:
      bootstrap - the bootstrap instance
    • onFatalError

      protected void onFatalError(Throwable t)
      Called by run(String...) to indicate there was a fatal error running the requested command. The default implementation calls System.exit(int) with a non-zero status code to terminate the application.
      Parameters:
      t - The Throwable instance which caused the command to fail.
      Since:
      2.0