Declaring @Resource and @EJB at the class level in Java EE6

后端 未结 2 533
故里飘歌
故里飘歌 2020-12-09 07:15

Is there any situation still ( given that Java EE6 has java:global/, app/, module/ naming standards) that necessitates declaring EJBs or Resources like the example below?

2条回答
  •  时光说笑
    2020-12-09 07:53

    Declaring a reference using a class-level annotation and declaring a reference using a java:module, java:app, or java:global name are distinct features.

    You would use a class-level annotation to declare a reference if you don't need injection but you don't want to use XML.

    You would use a java:module, java:app, or java:global name (regardless of how the reference is defined) if you want multiple components in the module, app, or server to have access to the same reference. For example, so that you are only required to define a binding for the reference once rather than repeating the same binding information for each identical binding in the module (or in the app or for all apps in the server).

提交回复
热议问题