Git Product home page Git Product logo

dropwizard-spring-annotations's Introduction

Dropwizard with Spring Annotations

This project provides support for integrating Spring with Dropwizard using annotations (i.e. no Spring XML configuration required). As of now, it supports Dropwizard 0.6+.

It was inspired and originally cloned+mirrored from Jared Stehler's dropwizard-guice library - https://github.com/jaredstehler/dropwizard-guice. Like dropwizard-guice, it uses classpath scanning courtesy of the Reflections project to discover Dropwizard objects (Resources, HealthChecks, Tasks and Managed) to install into the Dropwizard environment upon service start.

Usage

Following the first two steps below is all you need to do to get this working.

  • Extend from AutoWiredService<? extends Configuration> rather than Service
  • In addition, annotate Dropwizard Resources, Tasks, HealthChecks and Managed with Spring's @Component annotation
  • Optionally, override createSpringApplicationContext() in your service class to provide custom initializations for any of your Dropwizard objects

The nice benefit of doing this is that your DropWizard objects will be able to use Spring's @Autowired annotations for dependency injection. You can provide any number of configuration classes annotated with Spring's @Configuration annotation in your application.

In addition, the library also registers the Dropwizard configuration object into Spring's bean registry. This allows you to auto-wire your Dropwizard configuration into any of your Dropwizard objects.

For e.g.

@Component
@Path("my-resource")
public class MyResource {

    private SampleServiceConfiguration configuration;

    @Autowired
    public MyResource(SampleServiceConfiguration configuration) {
        this.configuration = configuration;
    }
...
}

A good use case for this library might be to use Spring-Data within your DropWizard objects.

See the test classes located within src/test/java/com/github/pnayak/dropwizard/spring/test for an example.

To use in your Maven projects:

<dependency>
    <groupId>com.github.pnayak</groupId>
    <artifactId>dropwizard-spring-annotations</artifactId>
    <version>1.0.0</version>
</dependency>

dropwizard-spring-annotations's People

Contributors

chids avatar dehora avatar jaredstehler avatar jaredstehler-cengage avatar luciano-fiandesio avatar pnayak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.