开发者

Access ServletContext resources in CDI Extension

开发者 https://www.devze.com 2023-02-21 05:39 出处:网络
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 re

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 environm开发者_如何转开发ent, 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消