Java EE 5 dependency injection?

99封情书 提交于 2021-02-07 06:17:21

问题


Since Java EE 5 does not have CDI, how does DI work in here?

Can an EJB be injected with @EJB in a class that is a non-EJB? Can an EntityManager be injected with @PersistenceContext in a class that is a non-EJB (container managed not resource local EntityManager)? Or the only solution to bring the resources in non-EJB classes is by JNDI lookup?

By non-EJB class I mean a class that is not annotated with @Stateless/@Statefull or others.


回答1:


Taken from: http://www.oracle.com/technetwork/articles/javaee/injection-141192.html

Keep in mind that a Java EE 5 platform container can handle the injections transparently only when they are used on container-managed components, such as EJB beans, Servlets, and JavaServer Pages (JSP) technology tag handlers.

onjava has an article: http://onjava.com/pub/a/onjava/2006/01/04/dependency-injection-java-ee-5.html

It presents a readable table of which managed-components (per container) that support injection of what type of resources.



来源:https://stackoverflow.com/questions/13530409/java-ee-5-dependency-injection

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