I'm playing around with using a bean with using an @Inject constructor with arguments. Is it only valid to use a bean with one if it is in the Dependent scope? If I use any other scope I get an UnproxyableResolutionException.
@Dependent @UseConstructor public class Dog implements Serializable { private Bone bone; @Inject public Dog(Bone bone) { this.bone = bone; } }
In the spec I found this section
If the bean has a normal scope and the given bean type cannot be proxied by the container, as defined in Section 5.4.1, “Unproxyable bean types”, the container throws an UnproxyableResolutionException.
followed later by:
5.4.1. Unproxyable bean types
Certain legal bean types cannot be proxied by the container:
• classes which don't have a non-private constructor with no parameters,
• classes which are declared final or have final methods,
• primitive types,
• and array types.
If an injection point whose declared type cannot be proxied by the container resolves to a bean with a normal scope, the
container automatically detects the problem and treats it as a deployment problem.
And since the only built-in non-normal scope is dependent this seems to limit the usefulness of @Inject constructors with parameter injection points. Changing the constructor to an initializer method allows any scope.
I just want to make sure I'm not crazy and I'm reading everything correctly.... (still on 1.0)
Just add a second, protected, no-argument constructor that the container can use to instantiate its proxy.