CDI对象不可与注入的构造函数一起代理 [英] CDI object not proxyable with injected constructor
本文介绍了CDI对象不可与注入的构造函数一起代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试将参数注入CDI bean(ApplicationScoped)的构造函数时,遇到以下问题:
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();
}
使用默认构造函数,变量注入和postconstruct方法,一切正常
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
}
这篇关于CDI对象不可与注入的构造函数一起代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文