When trying to inject arguments into the constructor of a CDI bean (ApplicationScoped), I'm encountering the following issue:
Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001435: Normal scoped bean class xx.Config is not proxyable because it has no no-args constructor - Managed Bean [class xx.Config] with qualifiers [@Default @Named @Any].
at org.jboss.weld.bean.proxy.DefaultProxyInstantiator.validateNoargConstructor(DefaultProxyInstantiator.java:50)
at org.jboss.weld.util.Proxies.getUnproxyableClassException(Proxies.java:217)
at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:178)
However, I do have an injectable constructor on the class:
@Inject
public Config(ConfigLocator configLocator) {
defaultConfigPath = configLocator.getPath();
doStuff();
}
With a default constructor, variable injection and a postconstruct method, this all works fine, but I'd prefer the constructor injection in this case.
Any thoughts what is going wrong here?
We resolved similar problem splitting class into interface and implementation. In your case something like this:
public interface Config
{
// API here
}
@ApplicationScoped @Priority(0)
public class ConfigImpl implements Config
{
@Inject
public ConfigImpl(ConfigLocator configLocator) { ... }
// API implementation here
}