Code Monkey home page Code Monkey logo

dropwizard-spring's Introduction

Dropwizard/Spring

Codeship Status for nhuray/dropwizard-spring

Welcome to the Dropwizard/Spring project

Introduction

Dropwizard is a Java framework for developing ops-friendly, high-performance, RESTful web services.

Spring is the most popular application development framework for enterprise Java™.

This project provide a simple method for integrating Spring with Dropwizard.

Versions

The current version of the project is 0.2.

dropwizard-spring Dropwizard Spring
master (0.3.2) 0.7.0 4.0.5.RELEASE
master (0.3.1) 0.6.2 3.1.4.RELEASE
0.2 0.6.0 3.1.3.RELEASE
0.1 0.5.1 3.1.1.RELEASE

Installation

To install Dropwizard/Spring you just have to add this Maven dependency in your project :

<dependency>
     <groupId>com.github.nhuray</groupId>
     <artifactId>dropwizard-spring</artifactId>
     <version>0.2</version>
</dependency>

Usage

The Dropwizard/Spring integration allow to automatically initialize Dropwizard environment through a Spring application context including health checks, resources, providers, tasks and managed.

To use Dropwizard/Spring you just have to add a SpringBundle and create your Spring application context.

For example :

public class HelloApp extends Service<HelloAppConfiguration> {

    private static final String CONFIGURATION_FILE = "src/test/resources/hello/hello.yml";

    public static void main(String[] args) throws Exception {
      new HelloApp().run(new String[]{"server", CONFIGURATION_FILE});
    }

    @Override
    public void initialize(Bootstrap<HelloAppConfiguration> bootstrap) {
      // register configuration, environment and placeholder
      bootstrap.addBundle(new SpringBundle(applicationContext(), true, true, true));
    }

    @Override
    public void run(HelloAppConfiguration configuration, Environment environment) throws Exception {
      // doing nothing
    }


    private ConfigurableApplicationContext applicationContext() throws BeansException {
      AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
      context.scan("hello");
      return context;
    }
}

In this example we create a Spring application context based on annotation to resolve Spring beans.

The SpringBundle class use the application context to initialize Dropwizard environment including health checks, resources, providers, tasks and managed.

Moreover the SpringBundle class register :

  • a ConfigurationPlaceholderConfigurer to resolve Dropwizard configuration as Spring placeholders (For example : ${http.port}).

  • the Dropwizard configuration with the name dw to retrieve complex configuration with Spring Expression Language (For example : #{dw.httpConfiguration}).

  • the Dropwizard environment with the name dwEnv to retrieve complex configuration with Spring Expression Language (For example : #{dwEnv.validator}).

Please take a look at the hello application located in src/test/java/hello.

License

The Apache Software License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.txt

dropwizard-spring's People

Contributors

acourtneybrown avatar nhuray avatar ursuad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropwizard-spring's Issues

Spring beans registered in this way have problems being used as qualifiers

I started using this library (or technically mimicking what it does as I couldn't find a way to extend it) and I stumbled across an issue with Spring referencing beans created in this way when referenced as a qualifier.

I submitted the issue to Spring with a test - you cna find it at https://jira.spring.io/browse/SPR-11915. They've just fixed it and they've going to backport it into the 3.2 and maybe 4.0 branches so you might want to take in their updates.

You'll see this issue as soon as you register a transaction manager with a custom name and try to use @transactional("name") somewhere else. I have a custom piece of YAML config where you have multiple databases, hence the need to at runtime configure multiple transaction managers.

Register DW Configuration as spring @Configuration bean?

Do you think there is a way to get the DropWizard Configuration class to be processed by the ConfigurationClassPostProcessor?

Then it would be possible to have @bean methods on the Configuration class itself that would initialize shared resources like the JDBI instance or a DataSource and make them available for autowiring. As it is now, if you wanted to have your JDBC settings in your YAML file, you'd need to have both a Dropwizard configuration class to receive the values, and a separate spring @configuration class to inject with @value and produce the DataSource.

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.