gpt4 book ai didi

spring - 如何在 Scala 中填充 Wicket @SpringBeans?

转载 作者:行者123 更新时间:2023-12-02 06:42:46 24 4
gpt4 key购买 nike

我有一个带有 @SpringBean 的 Wicket Page

class ScreenDetailsPage(parameters: PageParameters) extends BasePage(parameters) {
@SpringBean(name = "screenDAO") protected var screenDao: DAO[Screen] = null
assertNotNull(screenDao)

我发现@SpringBean没有填充。 screenDao 是 val 或 var、protected 或 private 都没有区别。

查找树,我发现 Component 的构造函数(间接)代表其子类初始化 @SpringBean,但随后对 null 的赋值则取消了它的初始化。但 Scala 要求进行赋值。

如何防止这种行为?

最佳答案

尝试

class ScreenDetailsPage(parameters: PageParameters) extends BasePage(parameters) {
@SpringBean(name = "screenDAO") protected var screenDao: DAO[Screen] = _
assertNotNull(screenDao)

我还没有尝试过这个,但我也在考虑启动一个 Wicket/Scala 项目,并看到 this blog entry ,这在其他方面也可能有用。

引用该博客的相关部分是

In addition, note that the field is assigned to an underscore (_), which tells the Scala compile to NOT initialize, but leave it at the default state (null in this case). This is required for the injection to work. If you assign it to null explicitly, you will overwrite the Spring bean as the injection will occur before the constructor of MyPage is executed.

关于spring - 如何在 Scala 中填充 Wicket @SpringBeans?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6395321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com