users@jersey.java.net

[Jersey] Re: Weld + Jersey + Tomcat?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 26 Jan 2011 11:07:08 +0100

Hi,

I cannot explain why that does not work for you. It seems that JNDI
lookup is working, so it should work in the Jersey code too.

Can you package things up as a maven app and send to the list and i
can investigate further?

The "injection of null" (which likely means no injection is occurring)
seems to imply that CDI is not managing the class.

Paul.

On Jan 25, 2011, at 8:08 PM, aaron_at_acsiri.com wrote:

> So I overrode ServletContainer with the following code and changed
> web.xml to use it:
>
> public class TomcatCDIServlet extends ServletContainer {
>
> private static final long serialVersionUID = 1L;
>
> private static final Logger LOG =
> Logger.getLogger(TomcatCDIServlet.class);
>
> @Override
> protected void initiate(ResourceConfig rc, WebApplication wa) {
> super.initiate(rc, wa);
>
> InitialContext ic =
> InitialContextHelper.getInitialContext();
> if (ic == null)
> return;
>
> try {
> Object beanManager =
> ic.lookup("java:comp/env/BeanManager");
> if (beanManager == null) {
> LOG.info("The CDI BeanManager is not
> available. JAX-RS CDI support is disabled");
> return;
> }
>
> rc.getSingletons().add(new
> CDIComponentProviderFactory(beanManager,rc,wa));
> LOG.info("JAX-RS CDI support is enabled");
> } catch (NamingException e) {
> LOG.log(Level.WARNING, "The CDI BeanManager is
> not available. JAX-RS CDI support is disabled.", e);
> }
>
> }
>
> }
>
> It now reports "JAX-RS CDI support is enabled" in the log but my bean
> is still @Injecting null.
>
> -Aaron