Spring integration for Dropwizard
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.



dropwizard-spring provides a clean, easy way to integrate the spring framework with dropwizard-based web service projects.

With dropwizard-spring you configure your dropwizard components (resources, healthchecks, jersey providers, managed objects, servlets, filters, etc.) entirely with spring, and tell the spring service which components to enable using a simple YAML configuration.

With dropwizard-spring it is not necessary to subclass com.yammer.dropwizard.Service, instead you reference the provided com.hmsonline.dropwizard.spring.SpringService class as your service class.

Maven Configuration

Maven Dependency

Dropwizard 0.7.0:


Dropwizard 0.6.2 (dropwizard-0.6.2 branch of this repository):


Maven Shade Plugin Configuration

This is required to have maven build a "fat," executable jar file.

						implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />

Sample YAML Configuration

# dropwizard-spring sample service configuration

# High level information that describes the application. This can be pulled into auto documentation tools like Swagger.
    rootServerName: www.example.com
    title: My Example Application
    description: Configure and use the application via this API
    contact: developers@example.com
    license: License type here
    licenseUrl: http://www.example.com/license
    termsOfServiceUrl: http://www.example.com/tos


    # Spring Context Type (Required)
    # either "web" or "app"
    appContextType: web

    # Resource Location Type (Required)
    # either "file" or "classpath"
    configLocationsType: file

    # Spring Config Locations (Required)
    # The location of one or more beans.xml files
       - conf/dropwizard-beans.xml

    # Servlet Filter
    # List of FilterConfiguration
            clazz: org.springframework.web.filter.DelegatingFilterProxy
            url: "/*"

    # List of ServletConfiguration
            clazz: org.apache.cxf.transport.servlet.CXFServlet 
            url: "/ws/soap/*"

    # JAX-RS Resources (Required if you want your service to do anything)
    # one or more spring beans that are JAX-RS resources
       - myRestResourceBean
       - anotherRestResourceBean

    # DW Health Checks (Optional, but recommended)
    # list of health check beans (must extend com.yammer.metrics.core.HealthCheck)
       - myHealthCheckBean

    # Jersey Providers (Optional)
    # list of Jersey Provider beans (ExceptionMappers, etc.)
        - myExceptionMapper

    # DW Managed Objects (Optional)
    # one or more instance of com.yammer.dropwizard.lifecycle.Managed
        - myManagedObjectBean

    # Jersey Life Cycles (Optional)
    # one or more life cycle instances
        - myLifeCycleBean
    # DW Tasks (Optional)
    # one or more instance of com.yammer.dropwizard.tasks.Task
        - myDropwizardTaskBean

    # Enabled/Disabled Jersey Features (Optional)
    # list of Jersey features to enable/disable
        - com.sun.jersey.config.feature.CanonicalizeURIPath

       - com.sun.jersey.config.feature.DisableWADL

Accessing Dropwizard Configuration Values from Spring

In some cases it may be necessary for a spring-configured component to access values in the dropwizard configuration or the com.yammer.dropwizard.config.Environment instance. For example, referencing the port on which the service is configured to run.

To allow this, at startup the dropwizard-spring service injects a special "dropwizard" bean into the application context that contains both the dropwizard environment and configuration objects.

The spring beans.xml example below illustrates how to reference values from the dropwizard yaml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                           http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
                           http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

	<bean id="helloResource" class="com.hmsonline.dropwizard.spring.sample.HelloResource">
		<property name="port">
		<util:property-path path="dropwizard.configuration.httpConfiguration.port"></util:property-path>

Using an IDE to run your dropwizard-spring service

If you'd like to run or debug your dropwizard-spring service with an IDE (e.g. IntelliJ IDEA) follow these simple steps:

  • Click Run -> Edit Configurations
  • Add a new configuration (Application)
  • Give it a name like Dropwizard Spring
  • For Main Class enter com.hmsonline.dropwizard.spring.SpringService
  • For Program arguments enter server conf/config.yaml
  • For Working directory enter the root directory of your webservice (the location of your pom.xml)
  • For Use classpath of module select your webservice application
  • Remove Make from Before launch
  • Click OK
  • Now, in the menu you can click Run -> Run 'Dropwizard Spring' or Run -> Debug 'Dropwizard Spring'