简体   繁体   English

用javax.inject替换com.google.inject

[英]Replacing com.google.inject with javax.inject

Is it true that javax.inject annotations can function as direct replacements for com.google.inject? javax.inject注释是否可以作为com.google.inject的直接替换?

So that, if I replaced all my current guice/gin annotations with those from javax.inject, my app would compile and run just fine? 所以,如果我用javax.inject替换所有我当前的guice / gin注释,我的应用程序将编译并运行得很好?

First, does javax.inject cover all the bases that google.inject cover? 首先,javax.inject是否覆盖了google.inject所涵盖的所有基础?

Yes, it will work fine. 是的,它会正常工作。 In fact the author of guice (Bob Lee) is a spec-lead for the javax.inject specification. 实际上,guice(Bob Lee)的作者是javax.inject规范的规范引导者。

javax.inject.Inject does not have the optional attribute, so if you want an optional dependency, you'd have to use the guice annotation. javax.inject.Inject没有optional属性,因此如果你想要一个可选的依赖项,你必须使用guice注释。

Actually, I have chosen to refrain from switching to javax.inject, because I find the spec much minimalistic in comparison to what Guice provides (which I use): 实际上,我已经选择不转换到javax.inject,因为我发现规范与Guice提供的内容(我使用的)相比非常简约:

  • @Optional as mentioned by @Bozho @Optional提到的@Optional
  • @ImplementedBy which is very useful when you want to reduce the number of explicit bindings (for code clarity) and when you want to be able to easily override the default @ImplementedBy binding if you need (eg for integration tests). @ImplementedBy ,当你想减少显式绑定的数量(代码清晰度)以及你希望能够在需要时(例如集成测试)轻松覆盖默认的@ImplementedBy绑定时非常有用。

There are probably others but for me these 2 are showstoppers already. 可能有其他人,但对我来说这两个已经是showstoppers。

The question is quite old but... FYI: you can automatically check that on apiwave . 这个问题已经很老了,但是......仅供参考:你可以在apiwave上自动检查

By learning with past changes we see that com.google.inject.Inject can be replaced by javax.inject.Inject . 通过了解过去的更改,我们发现com.google.inject.Inject可以替换为javax.inject.Inject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM