setter 注射指南 +便门
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 Wicket,但我假设您的 Wicket 网页上有各种带有
@Inject
注释的内容,是吗?所以,你有几个选择;按优先顺序排列:
@Inject
您的User
,一种选择是使用@注释
,然后在您的页面中,只需A
的构造函数注入@Inject
将A
或Provider
注入网页。@Inject
注入到您的网页中,将MembersInjector
(称为aMembersInjector
),然后在创建A< /code> 对象调用
aMembersInjector.injectMembers(a)
来导致所有 setter 注入发生。@Inject
注入到您的网页Injector
中,并在创建A
后调用Injector.injectMembers(a)
>。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:
@Inject
ing yourUser
, one option is to annotate the constructor ofA
with@Inject
and then in your page, just@Inject
either anA
or aProvider<A>
into web page.@Inject
into your web page aMembersInjector<A>
(call itaMembersInjector
) and then after you create yourA
object callaMembersInjector.injectMembers(a)
to cause all the setter injection to happen.@Inject
into your web page theInjector
and callInjector.injectMembers(a)
after you create yourA
.我不太确定你在问什么。无论如何,请尝试查看
查看是否有任何示例可以阐明您的问题。
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.