users@glassfish.java.net

Re: CDI producer field question

From: <glassfish_at_javadesktop.org>
Date: Wed, 14 Jul 2010 13:56:41 PDT

If you do, however, have a use case that you have a class that also has a producer of its default instances:

[code]
public class SomeClass {

    @Produces
    public static SomeClass produce() {
    // whatever, some init that doesn't work well in constructors (see http://seamframework.org/Community/NormalscopedBeansAndConstructors)
    }
}
[/code]

you would also get the ambiguity error. What you can do is:
a) introduce a constructor so that there is no default one, and no constructor is annotated @Inject - this makes the class violate the bean contract, and will not be discovered as bean; it producer, however, will be and as it is static, it can be called; I think that a private default constructor would also do the trick
b) you can write a portable extension that vetoes this particular bean class during bean discovery; you have experience with portable extensions in glassfish, judging by some other post on this forums ;d
[Message sent by forum member 'szczyp']

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