ef-labs / vertx-jersey

Run jersey in vert.x
MIT License
150 stars 47 forks source link

Spring as dependency injection framework #46

Open chrsoo opened 8 years ago

chrsoo commented 8 years ago

Hi,

I am trying to figure out how to best use vertx-jersey with Spring as the dependency injection framework. Any ideas how to accomplish this without too much of a hassle?

Perhaps the easiest way is to leverage the existing HK2 spring-bridge and use HK2?

Note that I only want to use Spring for basic dependency injection to port an existing JAXRS application. The idea is not to use Spring MVC etc.

adrianluisgonzalez commented 8 years ago

Yeah, I think the spring-bridge is the way to go. You can take a look at the guice-bridge for an example.

https://github.com/englishtown/vertx-jersey/blob/develop/vertx-jersey/src/main/java/com/englishtown/vertx/guice/GuiceJerseyServer.java#L39

If you want to submit a PR with Spring bridge support that would be great.

jogardi commented 7 years ago

I was able to integrate with spring dependency injection. First I copied and pasted the AutowiredInjectResolver class from jersey's GitHub into my project. Finally I just added an instance of this Binder to the service locator:

I think that adding these classes to vertx-jersey would make integrating with spring a lot easier but it is probably not worth introducing a dependency on Spring. However, we could also put these classes in a separate library or just add an example.