可以将dagger2与球衣一起使用的方式与使用guice的方式相同吗? [英] Is it possible to use dagger2 with jersey the same way it is possible with guice?

查看:123
本文介绍了可以将dagger2与球衣一起使用的方式与使用guice的方式相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像使用guice一样使用dagger2和球衣?

Is it possible to use dagger2 with jersey the same way it is possible with guice?

是否有dagger2 servlet或dagger2 jersey项目?

Is there any dagger2 servlet or dagger2 jersey project?

推荐答案

因此,简短的答案是没有.要在您的应用程序中获取Jersey的所有功能,没有很好的方法.

So, short answer is no, there is not a great way to do this while getting all of the features of Jersey in your application.

但是,有一些方法可以部分地做到这一点.您可以简单地在应用程序servlet中注册资源(在此处查看示例

However, there are ways to partially do this. You can simply register your resource in an application servlet ( see an example of that here https://github.com/cogman/gluews/blob/master/src/main/java/com/cogman/glue/GlueApplication.java )

使用这种方法会失去的是泽西在战场上注入的魔法物品,例如@Context.您仍然可以通过将它们添加到需要它们的方法签名中来获得这些东西,只是在字段级别上不容易做到这一点.

What you lose with this approach are the Jersey injected magic things at the field level, such as @Context. You can still get at these things by adding them to the method signatures that need them, you just can't easily do this at a field level thing.

此方法的另一个缺点是,所有资源实际上都是单例.如果您的资源是仅用于处理请求的简单对象,那就没什么大不了;如果您的资源在其上存储任何状态,就不那么重要了.

The other downside to this approach is that all resources become effectively singletons. Not a big deal if your resources are simple objects that simply service requests, a big deal if your resources are storing any sort of state on them.

这篇关于可以将dagger2与球衣一起使用的方式与使用guice的方式相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆