-
1. Re: to be or not to be (overloading the constructor)
banzeletti Aug 23, 2012 11:15 AM (in response to paul_)Since Seam3 is an extension to CDI I took a glimpse into the CDI spec. According to JSR-299 (CDI), 3.1.1 Which Java classes are managed beans?, the following conditions must apply:
...
* it has an appropriate constructor, either:
** the class has a constructor with no parameters, or
** the class declares a constructor annotated @Inject (Remark: as far as I know, a constructor that relies on injectable parameters)
...
From the example code above I believe that ýour classA does not meet the "constructor condition" and, as a consequence, is not tread as a managed bean, which makes it hard for WELD to resolve the @Inject classA statement in classB, resulting in the error message. So maybe a constructor with no parameters is the appropriate solution. I would also recommend to use the standard class naming convention which requires uppercase letters for the first letter of a class name: ClassA instead of classA.
As far as the "parametrized" constructors are concerned, they seem to need the @Inject annotation. In your case, the solution would probably be something like "class X { @Produces String testString = "test"; } class A {private String test; @Inject A(String s) { this.test = s; } }"...