当拦截器存在时,EJB 注入失败
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想取得进展,您可以尝试使用与拦截器绑定绑定的基于 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.