在 POJO 中使用依赖注入来注入 EJB [英] Using Dependency Injection in POJO's to inject EJB's

查看:40
本文介绍了在 POJO 中使用依赖注入来注入 EJB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用@EJB 注释将 ejb 注入 pojo 中?如果是,我是否必须在 JBoss 服务器上设置任何特殊的东西才能使其工作?

Is it possible to inject ejb's into pojo's using the @EJB annotation? If it is, do I have to set up anything special on a JBoss server to make it work?

请让我们不要讨论这样做背后的基本原理 - 我只是想破解一些旧代码以使其工作:-)

Please let us not discuss the rationale behind doing this - I am just trying to hack some old code to make it work :-)

推荐答案

是的,如果您能让 JBoss 为您创建 Pojo.

Yes, if you can make JBoss create the Pojo for you.

您的问题是您可能调用 new 来创建 Pojo,而框架无法拦截它,这就是忽略 @EJB 的原因.

Your problem is that you probably call new to create the Pojo and the framework can't intercept this which is why @EJB is ignored.

解决方案是使用工厂来创建您的 Pojo,并将 EJB 告诉工厂,以便它可以在返回新 Pojo 之前设置它们.

The solution is to use a factory to create your Pojos and tell the factory about the EJBs, so it can set them before returning the new Pojo.

这篇关于在 POJO 中使用依赖注入来注入 EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆