setter 注射指南 +便门

发布于 2024-08-31 19:00:45 字数 140 浏览 5 评论 0原文

我有一个 Wicket 网页,我在其中创建了 A 类的新对象: A a = new A(用户u);

在AI中希望有setter注入,但这实际上没有完成。我听说必须提供一个空的构造函数,但是怎么可能同时拥有一个带有 setter 注入的非空构造函数呢?

I have a Wicket Web Page where I create a new Object of class A:
A a = new A(User u);

In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non - empty constructor with setter injection?

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

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

发布评论

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

评论(2

摇划花蜜的午后 2024-09-07 19:00:45

我不熟悉 Wicket,但我假设您的 Wicket 网页上有各种带有 @Inject 注释的内容,是吗?

所以,你有几个选择;按优先顺序排列:

I'm not familiar with Wicket, but I assume that you've got various things on your Wicket web page annotated with @Inject, yes?

So, you have a few options; in order of preference:

  • If you're @Injecting your User, one option is to annotate the constructor of A with @Inject and then in your page, just @Inject either an A or a Provider<A> into web page.
  • You can @Inject into your web page a MembersInjector<A> (call it aMembersInjector) and then after you create your A object call aMembersInjector.injectMembers(a) to cause all the setter injection to happen.
  • You can @Inject into your web page the Injector and call Injector.injectMembers(a) after you create your A.
心奴独伤 2024-09-07 19:00:45

我不太确定你在问什么。无论如何,请尝试查看

查看是否有任何示例可以阐明您的问题。

I'm not exactly sure what you're asking. Regardless, try taking a look at

at see if any examples there shed light on your problem.

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