如何使用 Weld 注入外部 API bean - JSR-299

发布于 2024-09-29 13:51:11 字数 275 浏览 0 评论 0原文

我很清楚如何使用 Weld 注入我的域中的对象(我可以访问源代码)。您只需使用@Named 和@ApplicationScoped 注释实现,然后使用@Inject 注释目标属性即可注入实现。

但是,不确定如何注入我无权访问其源代码的类的实现。例如,我正在使用推土机。 Dozer 映射器是针对接口(Mapper)进行编程的,我希望 Weld 注入实现(DozerBeanMapper),但由于我无法访问源代码,因为我使用的是 .jar 依赖项,因此无法对其进行注释。

关于如何实现这一目标有什么想法吗?

It's clear to me how to inject an object which is in my domain (I have access to the source) using Weld. You just annotate the implementation with e.g. @Named and @ApplicationScoped, and then annotate the target attribute with @Inject to get the implementation injected.

However, not sure how can I inject implementations of classes which I don't have access to its source code. For example, I am using Dozer. Dozer mapper is programmed against an interface (Mapper) and I want Weld to inject the implementation (DozerBeanMapper), but since I don't have access to the source cause I am using a .jar dependency, I cannot annotate it.

Any ideas on how to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2024-10-06 13:51:11

POJO 中嵌入的注释是内部配置。内部配置和第三方组件不能混合。外部配置(例如beans.xml)是唯一的方法。您应该检查 Weld 的文档以了解外部配置。

Annotations embedded within POJOs is the internal configuration. Internal configuration and 3rd party components don't mix. External configuration(such as beans.xml) is the only way. You should check the document of Weld for external configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文