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的构造函数(间接)代表其子类初始化@SpringBeans,但是对null的赋值是uninitializing它.但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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。