users@glassfish.java.net

Weld/CDI issues with ManagedBeans, _at_Produces methods.

From: <glassfish_at_javadesktop.org>
Date: Tue, 05 Jan 2010 03:58:58 PST

Hi.

I'm attempting to get CDI working in a webapp in glassfish v3. Basic @Inject injection and activating alternatives are working, but any @ManagedBean that is injected with an object produced by a @Produces method is failing.

Consider the following code for the producer method:

@ManagedBean("Producer")
public class Producer {

    private Platform platform;

    @PostConstruct
    public void postConstruct() {
        platform = getPlatform();
    }

    /** Identify platform using database. */
    private Platform getPlatform() {...}

    @Produces
    public FirewallService getFirewallService() {
        return new FirewallService(platform);
    }
}

and the following code for the bean being injected with the object being produced:

@ManagedBean("ConfigurationBean")
public class ConfigurationBean extends AbstractBean<Configuration> {

    @Inject
    private FirewallService firewallService;
    ...
}

I'm using JNDI from my JAX-RS resources to obtain references to the @ManagedBeans. It is successful for any @ManagedBean without injection, with injection and inject with alternatives activated. When I request a @ManagedBean injected using a producer method, I only get the following error:

javax.naming.NamingException: Lookup failed for 'java:module/ConfigurationBean' in SerialContext [Root exception is javax.naming.NameNotFoundException: No object bound to name java:module/ConfigurationBean]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)

I get no error from Weld. Under debugging I can see that the producer method is being called. Also, I can introspect the JNDI context when debugging and see the 'java:module/ConfigurationBean' name when listing the names available under the 'java:module' context.

While I can see how to get this working now using alternatives, I may want to use @Produces methods in the future.
[Message sent by forum member 'beamso' (beamso_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=378783