Java EE 6: module and application scopes of java:comp/env?
I would like to get feedbacks about
application-scoped and module-scoped resource/EJB references (in
java:comp/env) which are being discussed in Java EE 6 JSR.
As you know, when we define simple
environment entries or refer to data sources or EJBs we need to
java:comp/env ENC(Environment Naming Context) entries like
or via annotations on the component
@EJB(name="ejb/myBean", beanInterface= some.package.MyBeanInterface.class)
Then we use these
entries in the application code with lookup or injection. Also it may
need to map these entries to the global JNDI names of the real
physcial resources via vendor-specific way or mapped name elements.
This is a good indirection facility rather than using global JNDI
names directly in the code.
Current limitation is that EJB module
can only have component-scoped(per-bean) namespace so that you need
to define the same references and mappings again and again for each
EJB. This is different from web module which has only module scope.
Therefore it's hard to define shared configuration/references at
module level and it's especially inconvenient for module default
Also there is no notion of application
scope for sharing between modules inside one application. So it's
difficult to share those between modules.
As we try to enable packaging EJBs in
web module, it's also an option to add component scope to web
module so each EJB has its own scope. I'm not sure that we need to
add this for servlet components either.
Even though there are multiple scopes,
you don't need to find out exactly where the entries are defined.
General scope rule will be applied here. When you looking up with
java:comp/env/myDataSource or refering to it via injection,
this will try to find the narrow scope first (component scope ->
module scope -> application scope).
I would like to hear from you about
- Do we need the module scope in EJB module?
- Do we need to introduce the application scope?
- Do we also need the component scope in Web module?
Please give us any use cases or reasons
if you have. Your feedbacks are important to add these extensions to
Java EE 6.