访问 CDI 扩展中的 ServletContext 资源
我面临以下情况:我编写了一个 CDI 扩展,我想用它以编程方式将其他 bean 注册到 BeanManager 中。我已经实现了扩展并在 META-INF/services
文件夹中注册。到目前为止,一切正常,我可以跟踪调用此方法的容器:
public class TestCdiExtension implements Extension {
public void observeAfterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
// Code goes here
}
}
我现在的问题是:要确定应注册哪些 bean,我需要访问 CDI 所在的当前 Web 应用程序的 ServletContext
正在运行。
据我了解,您可以在没有servlet环境的情况下完全使用CDI,因此不存在硬链接。但是:我如何根据 ServletContext 中的内容来注册其他 bean?
使用扩展是正确的方法吗?还有其他(更好的?)解决方案吗?
I'm facing the following situation: I have written a CDI extension, with which I want to programatically register additional beans into the BeanManager
. I've already implemented the extension and registered in in the META-INF/services
folder. Everything works fine so far and I can trace the container calling this method:
public class TestCdiExtension implements Extension {
public void observeAfterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
// Code goes here
}
}
My problem now is this: To determine which beans should be registered, I need access to the ServletContext
of the current web application in which CDI is running.
I understand that you can use CDI completely without a servlet environment, so there is no hard link. However: How can I do the job of registering additional beans depending on what's in the ServletContext
?
Is using an extension the correct way at all? Is there any other (better?) solution of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论