Using Dependency Injection in POJO's to inject EJB's

家住魔仙堡 提交于 2019-12-24 11:35:54

问题


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 :-)


回答1:


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

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.

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.




回答2:


Not sure, but EJB 3.1 should allow this.



来源:https://stackoverflow.com/questions/1648888/using-dependency-injection-in-pojos-to-inject-ejbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!