java - 为什么 Quarkus 不扫描 JakartaEE bean?
问题描述
我正在从部署在 JBoss 上的 JavaEE/JakartaEE (v. 7.0) 应用程序迁移到 Quarkus。
我已经删除了所有 JEE 和 JBoss 依赖项,并将它们替换为 Quarkus 依赖项。现在,当我使用mvn compile quarkus:dev
Quarkus 文档中指定的 command: 启动应用程序时,我收到很多错误,如下所示:
[1] Unsatisfied dependency for type com.freesoft.diba.jeeop.cert_proxy.acme.database.NonceRepository and qualifiers [@Default]
[ERROR] - java member: com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature#nonceRepository
[ERROR] - declared on CLASS bean [types=[java.lang.Object, com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature], qualifiers=[@Default, @Any], target=com.freesoft.diba.jeeop.cert_proxy.acme.AcmeProtocolFeature]
该课程AcmeProtocolFeature
如下:
@Provider
public class AcmeProtocolFeature implements DynamicFeature {
@Inject
Logger logger;
@Inject
PolicyHandler policyHandler;
@Inject
NonceRepository nonceRepository
[...]
该课程NonceRepository
如下:
public class NonceRepository {
@Inject
@PersistenceContext(unitName = "acme")
EntityManager em;
在应用程序的先前版本(JEE 版本)中,一切都运行良好。我想知道为什么这不再像预期的那样工作了,因为据我所知,Quarkus 实现了所有 JavaEE/JakartaEE 标准?!
解决方案
As it is stated in Quarkus documentation, the classes that are not having a bean defining annotation are not discovered.
Bean classes that don’t have a bean defining annotation are not discovered. This behavior is defined by CDI. But producer methods and fields and observer methods are discovered even if the declaring class is not annotated with a bean defining annotation (this behavior is different to what is defined in CDI)
In JavaEE/JakartaEE, if a class did not have specified any bean defining annotation, then the it will be considered by default annotated with @Dependent
, so basically, this is why the JavaEE/JakartaEE version of the application worked well, and the Quarkus one did not work at all.
The solution would be to explicitly specify a bean defining annotation on top of each class that you want to inject further, specifically in this scenario, the class NonceRepository
should be annotated at least with the @Dependent
annotation.
推荐阅读
- python - 单击开始按钮时如何退出标题屏幕?
- php - 在模型中进行自定义查询的最佳实践
- docker - 在 dockerfile 中复制一个 repo 克隆
- jquery - Jquery - 检查不同父母的必填字段
- reactjs - 可以在 JSX 中使用 react hooks 吗?
- asp.net-core - 在服务器上发布 asp.net 核心项目时出现问题
- php - 在php中将新行编码从\r\n更改为\n
- node.js - mongoose onsave - 卡住了
- python - 无法破解 3 个数字的 GCD 的 Python 代码?
- c++ - 如何包含 <> 忽略系统默认头文件路径(usr/include)?