在 CDI 中注入带有限定符的字符串
我正在尝试做简单的事情。在 CDI 中注入合格的String
(或File
)。
所以我有一个限定符:
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD,METHOD,PARAMETER,TYPE})
@Qualifier
public @interface FilesRepositoryPath {}
我有一个生产者:
public class FilesRepositoryPathProducer {
@Produces
@FilesRepositoryPath
public String getRepositoryDirectory() {
return "path.taken.from.configuration";
}
}
我正在尝试使用它:
@ApplicationScoped
public class FilesRepository {
@Inject
public FilesRepository(@FilesRepositoryPath String filesDirectory) {
//Do some stuff
}
}
但是,WELD 无法实例化这个 bean。我收到一个异常:
org.jboss.arquillian.impl.event.FiredEventException: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001410 The injection point [field] @Inject private za.co.fnb.commercial.dms.file.FilesRepositoryBeanTest.repo has non-proxyable dependencies
我知道 String
是不可代理的,但为什么 WELD 要创建代理?它具有 @Dependent
范围,因此据我所知,它无论如何都不应该创建代理。我怎样才能让它发挥作用?
I'm trying to do simple thing. Inject qualified String
(or File
) in CDI.
So I have a qualifier:
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD,METHOD,PARAMETER,TYPE})
@Qualifier
public @interface FilesRepositoryPath {}
I have a producer:
public class FilesRepositoryPathProducer {
@Produces
@FilesRepositoryPath
public String getRepositoryDirectory() {
return "path.taken.from.configuration";
}
}
And I'm trying to use it:
@ApplicationScoped
public class FilesRepository {
@Inject
public FilesRepository(@FilesRepositoryPath String filesDirectory) {
//Do some stuff
}
}
However, WELD cannot instantiate this bean. I am getting an exception:
org.jboss.arquillian.impl.event.FiredEventException: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001410 The injection point [field] @Inject private za.co.fnb.commercial.dms.file.FilesRepositoryBeanTest.repo has non-proxyable dependencies
I know String
is unproxable, but why WELD wants to create a proxy? It has @Dependent
scope, so AFAIK it shouldn't create proxy anyway. How can I make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要默认构造函数
you need the default constructor