I want to have a configuration parameter injected this way:
public class MyManagedBean {
@Inject
public MyManagedBean(@Named(\"user\") String user){
It looks like you need a default (no-arg) constructor for your MyManagedBean
to make it proxyable. I am not really sure about why it is needed, since MyManagedBean
is a @Dependent
bean and so is not proxied AFAIK; I do not know even why a proxyable bean needs a default constructor, to be honest This seems to be an implementation detail or a little point from CDI specification that was ignored. Anyway, I bet it can make a good new question :)
EDIT: I discovered why a proxyable bean needs a default construction. It is no mistery, actually: since the proxy of a bean is a subclass of the same bean, the proxy needs to call a super()
constructor in its own construction. If it has no non-private default constructor, it does not know which constructor to call. One can even imagine a scenario where the injected constructor is called to create the proxy, but I do not know which kind of complexity it can add to a CDI implementation; it may not be so easy to do...