为什么 TestNG 交付中的 Guice 不能识别 @javax.inject.Inject,而 com.google.inject 包中的 Guice 可以识别?

发布于 2024-10-09 00:35:47 字数 931 浏览 0 评论 0原文

我正在尝试吉斯。我做了一个简单的示例,与 Guice 入门 手册。

但一时间没效果,说道:

找不到合适的构造函数 在 mypack.ServiceUser 中。课程必须 有其中之一(且只有一个) 用 @Inject 注释的构造函数或 一个零参数构造函数是 不是私人的。在 mypack.ServiceUser.class(ServiceUser.java:14) 找到 mypack.ServiceUser 时

问题出在导入中。我将 Google Guice 和 TestNG 附加到该项目中。我从 org.testng.guice 包中导入了类。但是注释Inject是从javax.inject包导入的。在我将导入更改为 org.testng.guice.Inject 后,我​​的程序开始运行。

但在那之后我更多地接触了进口产品。我将所有 org.testng 导入更改为 com.google.inject。该程序仍然有效。之后,我回到@Inject注释并将其导入更改为javax.inject.Inject(就像我的第一个损坏版本一样)。在那之后该程序仍然有效。

我再次检查了:TestNG 包中的 Guice 不能与 javax.inject.Inject 一起使用,而 google 包中的 Guice (com.google.inject) 则可以正常使用。

为什么这么奇怪?

ps 我使用 Guice 和 TestNG 的最新版本(guice-3.0-rc1 和 testng-5.14.5)。

I'm trying Guice. I made a simple example which is very similar to the example in the Guice Getting Started manual.

But it didn't work for some time and said:

Could not find a suitable constructor
in mypack.ServiceUser. Classes must
have either one (and only one)
constructor annotated with @Inject or
a zero-argument constructor that is
not private. at
mypack.ServiceUser.class(ServiceUser.java:14)
while locating mypack.ServiceUser

The problem was in imports. I attached both Google Guice and TestNG to the project. And I imported classes from org.testng.guice package. But annotation Inject was imported from the javax.inject package. After I changed that import to org.testng.guice.Inject my program began working.

But after that I played with imports a little more. And I changed all org.testng imports to com.google.inject. The program still worked. After that I went back to the @Inject annotation and changed its import to javax.inject.Inject (as it was in my very first broken version). And the program worked even after that.

I checked ones again: Guice from TestNG packages doesn't work with javax.inject.Inject while Guice from google packages (com.google.inject) works normally with it.

Why is it so weird?

p.s. I use last versions of both Guice and TestNG (guice-3.0-rc1 and testng-5.14.5).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澜川若宁 2024-10-16 00:35:47

简短的回答是:@Guice 仍在进行中,并且正在邮件列表上进行设计,因此它仍处于实验阶段。

另外,您正在使用未记录的软件包,这些软件包是为 TestNG 内部使用(org.testng.guice)保留的。

我今天刚刚推送了新版本,大家可以在 http://testng.org/beta 下载,

注意这个新版本不再有 org.testng.guice,因此请确保每当您需要 Guice 符号时,都从 com.google.inject 导入它们。

如果您有任何其他问题/疑虑,请在 testng-users 邮件列表上发帖。

谢谢。

The short answer is: @Guice is still a work in progress and being designed on the mailing-list as we speak, so it's still experimental.

Also, you are using undocumented packages that are reserved for TestNG's internal use (org.testng.guice).

I pushed a new version just today, you can download it at http://testng.org/beta

Note that this new version no longer has org.testng.guice, so make sure that whenever you need Guice symbols, you import them from com.google.inject.

Please post on the testng-users mailing-list if you have any more questions/concerns.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文