wicket @SpringBean 无法创建 bean

发布于 2024-09-08 22:31:20 字数 456 浏览 6 评论 0原文

我有一个关于 Eclipse、Wicket、Spring、Hibernate 的项目。一切正常,除了:当我尝试

public class SortableContactDataProvider extends SortableDataProvider<User>
{
    @SpringBean
    private Service service;

    public Iterator<User> iterator(int first, int count)
    {
        //SortParam sp = getSort();
        return service.findAllUsers().subList(0, 15).iterator();
    }
...

服务变量为空?在任何其他地方,当我使用此构造“服务”时,它不为空并且运行良好。请帮我解决这个问题。

I have a project on Eclipse, Wicket, Spring, Hibernate. Every thing works normaly except : when I try

public class SortableContactDataProvider extends SortableDataProvider<User>
{
    @SpringBean
    private Service service;

    public Iterator<User> iterator(int first, int count)
    {
        //SortParam sp = getSort();
        return service.findAllUsers().subList(0, 15).iterator();
    }
...

the service variable is null? In any another places when I use this constuction "service" is not null and working well. Please help me to solve this problem.

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

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

发布评论

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

评论(2

愛放△進行李 2024-09-15 22:31:20

@SpringBean仅适用于组件的任何子类。

中执行以下操作,

您需要在构造函数Wicket 1.4

  InjectorHolder.getInjector().inject(this);

Wicket 1.5+

  org.apache.wicket.injection.Injector.get().inject(this);

请参阅“通用 IDataProvider 实现”@ http://stronglytypedblog.blogspot.com/2009/03/wicket-patterns-and-pitfalls-1.html

享受

@SpringBean works only in any Subclass of Component.

You need to do the following in your Constructor

Wicket 1.4

  InjectorHolder.getInjector().inject(this);

Wicket 1.5+

  org.apache.wicket.injection.Injector.get().inject(this);

See 'generic IDataProvider implementation' @ http://stronglytypedblog.blogspot.com/2009/03/wicket-patterns-and-pitfalls-1.html

Enjoy

离不开的别离 2024-09-15 22:31:20

对于那些 Wicket/Spring 环境的新手来说,有更多的上下文 - 正如 bert 所指出的,@SpringBean 仅适用于组件的任何子类,因此您需要手动驱动注入。这是一个 2 步过程:

在您的类中驱动注入,如下所示:

public class SortableContactDataProvider extends SortableDataProvider<User>
{
    @SpringBean
    private Service service;

    public SortableContactDataProvider(){
        Injector.get().inject(this); // set up the injection
    }

    public Iterator<User> iterator(int first, int count)
    {
        return service.findAllUsers().subList(0, 15).iterator();
    }
}

并确保在 Wicket 应用程序中设置注入器 - 类似于:

public WicketApplication 

    @Override
    protected void init() {
        // make sure Spring injector is available and set up
        getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    }
}

A bit more of context for those who are newbies to Wicket/Spring environment - as bert, pointed out, @SpringBean works only in any Subclass of Component so you'll need to drive the injection manually. This is a 2 step process:

Drive the injection in your class, something as:

public class SortableContactDataProvider extends SortableDataProvider<User>
{
    @SpringBean
    private Service service;

    public SortableContactDataProvider(){
        Injector.get().inject(this); // set up the injection
    }

    public Iterator<User> iterator(int first, int count)
    {
        return service.findAllUsers().subList(0, 15).iterator();
    }
}

And make sure the Injector is set up in Wicket application - something like:

public WicketApplication 

    @Override
    protected void init() {
        // make sure Spring injector is available and set up
        getComponentInstantiationListeners().add(new SpringComponentInjector(this));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文