title: Accessing servlet context parameters from a CDI extension
body: <p>I'm trying to write a CDI extension that needs to access the context parameters defined in web.xml via <code>&lt;context-param&gt;</code>. I think there are two ways of doing this:</p>
  
  <ul>
  <li>Somehow get the <code>ServletContext</code> and call <code>getInitParameter()</code></li>
  <li>Manually parse the <code>web.xml</code></li>
  </ul>
  
  <p>Unfortunately I need the the <code>ServletContext</code> for both solutions and getting it doesn't seem to be possible. The problem here is that some containers startup CDI before the <code>ServletContext</code> is created. And even if the <code>ServletContext</code> would be available before CDI starts up, there seems to be no way to access it from the CDI extension. I experimented with a <code>ServletContextListener</code> that stores the <code>ServletContext</code> in a static <code>ThreadLocal</code>. This seems to work fine but it would create a memory leak as I'm unable to cleanup the <code>ThreadLocal</code> reliably.</p>
  
  <p>Two more comments before you answer:</p>
  
  <ul>
  <li>Using some other approach to read configuration parameters (like using JNDI) is no option for me as I'm trying to write a CDI extension for integrating with a 3rd party framework.</li>
  <li>I'm aware of the fact that there will be probably no soltion for this problem that is 100% portable between environments/containers. But I would be happy if I find a solution that works in most cases.</li>
  </ul>
  
  <p>Thanks! :)</p>