-
1. Re: Constructor question
mbogoevici Aug 27, 2010 11:26 AM (in response to nimo22)Hm, this is a compilation error. Are you sure that you're not invoking the no-arg constructor explicitely from anywhere in your code?
Apart from that, and completely unrelated to the compilation error - and I stress that :), you may need a no-arg constructor anyway, since your bean is normal-scoped (session-scoped) - and the framework will need to be able to create a proxy for it - read chapter 5.4 of the CDI specification for details. But, even then, this would show up at deployment time and not during compilation.
-
2. Re: Constructor question
asiandub Aug 27, 2010 5:40 PM (in response to nimo22)I can confirm that the above code compiles :-)
As Marius suggests:
- a compilation error should always be unrelated to any Weld issued
- a deployment error will be thrown by the container because MyBean is not proxyable
org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001400 Normal scoped bean org.jboss.weld.bean-flat-ManagedBean-class ...MyBean is not proxyable at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:127)
The example from the Weld-reference which you are quoting is not annotated, and therefore @dependent-scoped, which does not require the bean to be proxyable...
public class TextTranslator { private SentenceParser sentenceParser; private Translator sentenceTranslator;
-
3. Re: Constructor question
nimo22 Aug 30, 2010 2:35 AM (in response to nimo22)Hello Marius,
yes, you are right. I had overseen that I invoked the no-arg constructor explicitely from my Test-Code.
So to sum up:
When injecting constructor, should I use this:
Version 1:
public MyBean(){} @Inject public MyBean(OtherBean ob){ this.ob= ob; }
or that:
Version 2:
public MyBean(){} // Normally (without CDI), I also need the non-arg constructor. public MyBean(){} @Inject public MyBean(OtherBean ob){ this.ob= ob; }
In CDI, both versions work. Which version should I use? Does it make a difference?
-
4. Re: Constructor question
nimo22 Aug 30, 2010 2:38 AM (in response to nimo22)
you may need a no-arg constructor anyway, since your bean is normal-scoped (session-scoped)Okay, so I need to use version 2. However, using version 1 does not return a deployment error.