users@glassfish.java.net

CDI producer field question

From: <glassfish_at_javadesktop.org>
Date: Wed, 14 Jul 2010 13:12:34 PDT

CDI has the notion of producer fields.

A producer field is one that, as I understand it, can be used to bridge the worlds of CDI dependency injection and Java EE dependency injection.

I have a @SessionScoped object that contains an injection point. I want that injection point to receive the results of a producer field located in another class.

So:
[code]
// inside session scoped object
@Inject
private Frobnicator frobnicator;
[/code]
...and:
[code]
// somewhere else
public class FrobnicatorProducer {
  @Produces
  @EJB
  private Frobnicator frobnicator;
}
[/code]
In Glassfish 3.1 b09, deploying this combination results in Weld telling me that the injection point has several potential injections, and so deployment fails.

The possible injections are listed as the session bean itself as well as the bean produced by the producer field.

So what is the proper way for declaring a producer field in such a way that the @EJB it is "producing" is actually the only possible injection for a given injection point?

Weld's documentation has only this to say on the subject: http://docs.jboss.org/weld/reference/1.0.0/en-US/html/resources.html#d0e4373

Note that the only @EJB example here uses ejbLink, which I neither understand nor want to use.

Thanks,
Laird
[Message sent by forum member 'ljnelson']

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