Dropwizard with Spring Framework support for DI
We love Dropwizard and Spring framework. Unfortunately the existing solutions to bring together both technologies are outdated. We like Dropwizard latest version (yeah, the 0.7.0-SNAPSHOT).
And we love pragmatic programming models. The less we write, the more happiness we have. That's the reason this project was born.
Very soon kids...
-
Add the following both repos in your build.gradle file
repositories { maven { url 'http://oss.sonatype.org/content/repositories/snapshots' } maven { url 'http://repo.sindica.to/nexus/content/repositories/public-milestones/' } }
-
Add the following dependency
dependencies { compile 'sindica.to:dropwizard-spring:0.3.0-SNAPSHOT' }
-
Create your Dropwizard Application extending from sindica.to.dropwizard.spring.SpringApplication
package sindica.to.sample; import sindica.to.dropwizard.spring.SpringApplication; public class MyApp extends SpringApplication<MyConf> { public static void main(String[] args) throws Exception { new MyApp().run(args); } @Override public void onConfigureSpringContext(AnnotationConfigWebApplicationContext applicationContext) { //Scan your own packages for Spring beans with annotations //like @Component, @Repository, @Inject, @Autowired, etc applicationContext.scan("sindica.to.sample"); } }
-
Create the usual Dropwizard artifacts as always
package sindica.to.sample.resource; import org.springframework.stereotype.Component; import sindica.to.sample.model.Person; import javax.ws.rs.GET; import javax.ws.rs.Path; import java.util.List; @Path("/person") @Component public class PersonResource { @GET public List<Person> list() { //TODO: implement this... } }
The trick is to add the Spring's Annotations like @Component
-
Enjoy, hack, deliver, profit¡