开发者

How do I populate Wicket @SpringBeans in Scala?

I have a Wicket Page with a @SpringBean

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

and I find that the @SpringBean is not populated. It makes no difference if screenDao is val or var, protected or private.

Looking up the tree I find that the constructor of Component (indirectly) initialises @SpringBeans on behalf of its subclasses, but then the assignment to null is un开发者_如何学JAVAinitializing it. But the assignment is required by Scala.

How can I prevent this behaviour?


Try

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

I have not tried this, but am also thinking about starting a Wicket/Scala project, and saw this blog entry, which might be useful in other ways as well.

The relevant section quoted from that blog is

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜