When trying to inject arguments into the constructor of a CDI bean (ApplicationScoped), I\'m encountering the following issue:
Caused by: org.jboss.weld.exceptio
This example might help you :
@ApplicationScoped
public class Config {
private String defaultConfigPath;
@Inject
public Config(ConfigLocator configLocator) {
this.defaultConfigPath = configLocator.getPath();
doStuff();
}
// create a no-args constructor which is required for any scoped bean.
public Config() {
}
}
You need to have a public non-args constructor in the @ApplicationScoped
bean.
Note : The bean for this class will created only once and is maintained for the entire life of an application. This bean will shared among all the managed beans. @ApplicationScoped beans are singleton in nature.
The mentioned 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].
The possible reason for this is that a non-dependent scoped bean is required to provide a public no-args constructor for CDI, so that it can pick up the desired proxy bean at runtime.