-
1. Re: Private bean constructor?
mkouba Apr 24, 2014 1:57 AM (in response to sixtdeu)Hi sixtdeu,
please add some more info, e.g. what exception you get. A code snippet with your bean would be helpful as well. Also what application server and weld version do you use?
-
2. Re: Private bean constructor?
sixtdeu Apr 24, 2014 2:31 AM (in response to mkouba)Hi Martin,
the WAR cannot be deployt to the server (in my case WildFly). Just try to add an private default constructor to any CDI bean with scope other than dependent, inject it into an other bean and then deploy your application. Does it work?
E.g.
@RequestScoped
public class RequestScopedService
{
private RequestScopedService() {
}
}
org.jboss.weld.exceptions.DeploymentException: WELD-001410: The injection point [BackedAnnotatedField] @Inject private ....ScopePresenter2.requestScopedService has non-proxyable dependencies...
(...)
Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001436: Normal scoped bean class ....RequestScopedService is not proxyable because it has a private constructor private ....RequestScopedService() - Managed Bean [class ....RequestScopedService] with qualifiers [@Any @Default].
It is clear for me, that a private constructor could be a problem, when the container trys to create the proxy, but why there is this in the spec:
3.9 Bean constructors [bean_constructors]
When the container instantiates a bean class, it calls the bean constructor. The bean constructor is a default-access, public,
protected or private constructor of the bean class.
It cannot be that I'm the only one who tried it out with a private ctor?
-
3. Re: Private bean constructor?
mkouba Apr 24, 2014 3:01 AM (in response to sixtdeu)I see. Well, the private constructor with no parameters is really a problem here. "3.9. Bean constructors" is a more general section, 3.15. Unproxyable bean types adds some more restrictions for client proxies.
-
4. Re: Private bean constructor?
sixtdeu Apr 24, 2014 9:24 AM (in response to mkouba)Oh yes, now I see... The first 3.15 says is
"Certain legal bean types cannot be proxied by the container:
classes which don’t have a non-private constructor with no parameters,"
Thanks!