CDI——处理错误

发布于 2024-09-08 02:49:34 字数 252 浏览 2 评论 0原文

我正在将 Seam 2 支持的应用程序迁移到 CDI,对我来说最重要的事情之一就是保留错误处理。在 Seam 2 中,我只是用自己的异常处理程序替换了默认的异常处理程序,但在 CDI 中,我猜我必须使用拦截器。

由于使用拦截器需要我指定它将拦截调用的位置,因此我该如何设置?我主要想完成审核,因此当发生异常时,将其记录下来,然后向管理员发送通知(电子邮件、xmpp、短信、电话)。

当异常发生时,是否有一个我可以监听并采取行动的事件?

瓦尔特

I am migrating my Seam 2 powered application to CDI and one of the things that is critical for me to retain is the error handling. In Seam 2, I simply replaced the default exception handler with my own, but in CDI, I am guessing I'll have to use an Interceptor.

How would I set this up as using an Interceptor requires me to specify where it will intercept calls? I mostly want to accomplish auditing, so when an exception occurs, it is logged, then a notification (email, xmpp, sms, phone call) is sent out to administrators.

When an exception occurs, is there simply an event that I can listen for and act on?

Walter

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

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

发布评论

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

评论(1

痴者 2024-09-15 02:49:34

您使用的是 JSF2 吗?如果是,您可以在 web.xml 中注册一个 ExceptionHandlerFactory,而不是编写 Interceptor 如此处所述。在 CustomExceptionHandler 中,您可以捕获所有异常并以编程方式处理它们。
我在我的 JEE6-CDI-app 中使用这种方法,发现它相当不错。

Are you using JSF2? If yes, instead of writing an Interceptor, you could register an ExceptionHandlerFactory in your web.xml as described here. In a CustomExceptionHandler, you can catch all Exceptions and handle them programmatically.
I'm using this approach in my JEE6-CDI-app, find it quite okay.

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