当拦截器存在时,EJB 注入失败

发布于 2024-10-06 12:07:08 字数 851 浏览 5 评论 0原文

我在 JSF 应用程序中使用 DI 和拦截器时遇到问题。

我有一个支持 bean,它观察 JSF 事件并执行一些初始数据查找。在 JSF 页面中,bean 被注册为事件侦听器,如下所示:

<f:event type="preRenderView" listener="#{myBean.loadData}"/>

该 bean 非常先进,基本上如下所示:

@Named
@RequestScoped
public class MyBean {

    @EJB
    private SomeDao dao;

    public void loadData() { ... }

    public void performSomeStuff() { ... }

}

dao 已正确注入,并且在此之前一切都很好。现在我想执行一些在拦截器内完成的延迟加载(特定代码并不重要,因为当拦截器仅在调用上下文上继续时会出现相同的行为)。因此,在调用 PerformSomeStuff() 之前,我想确保所有数据均已加载:

    @Interceptors(MyInterceptor.class)
    public void performSomeStuff() { ... }

此时 EJB 不再被注入(NPE 显示...) - 对此有什么想法吗?

设置:

  • GlassFish 3.0.1
  • WELD-000900 1.0.1 (SP3)
  • Mojarra 2.0.2 (FCS b10)

提前致谢!

问候, 亚历克斯

I'm facing a problem when using DI and interceptors in an JSF app.

I have a backing bean that observes JSF events and performs some initial data lookup. In the JSF page the bean is registered as event listener as follows:

<f:event type="preRenderView" listener="#{myBean.loadData}"/>

The bean is pretty forward and looks basically like this:

@Named
@RequestScoped
public class MyBean {

    @EJB
    private SomeDao dao;

    public void loadData() { ... }

    public void performSomeStuff() { ... }

}

The dao is properly injected and everything is fine until here. Now I'd like to perform some lazy loading which is done within an interceptor (the particular code doesn't matter as the same behaviour shows up when the interceptor just proceed on the invocation context). So, before calling performSomeStuff() I'd like to ensure that all data is loaded:

    @Interceptors(MyInterceptor.class)
    public void performSomeStuff() { ... }

At this point the EJB doesn't get injected any longer (NPE shows up...) - any ideas on this?

Settings:

  • GlassFish 3.0.1
  • WELD-000900 1.0.1 (SP3)
  • Mojarra 2.0.2 (FCS b10)

Thanks in advance!

Regards,
Alex

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

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

发布评论

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

评论(1

情绪少女 2024-10-13 12:07:08

如果您想取得进展,您可以尝试使用与拦截器绑定绑定的基于 299 的拦截器,而不是 EJB 样式。如果该区域存在错误,让拦截器稍后运行可能会有所缓解。

If you wanted to make progress, you might try using 299-based interceptors tied in with an interceptor binding as opposed to the EJB-style. If there's a bug in the area, having your interceptor run a bit later might provide some relief.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文