The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Wonseok Kim

Wonseok Kim is a senior developer at TmaxSoft, South Korea. He works on the development of Tmax Application Server - very popular in Korea. He has been participated in JCP such as JSR 244 (Java EE 5) and JSR 220 (EJB 3.0). He is also a contributor to GlassFish project. Prior to Java EE he had developed NMS and OSS systems for telecommunications in Java. Now he has concerns primarily on EJB and persistence technologies and is working on them.

 

Wonseok Kim's blog

Java EE 6: module and application scopes of java:comp/env?

Posted by guruwons on June 5, 2008 at 8:47 PM PDT

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 specify java:comp/env ENC(Environment Naming Context) entries like below.

    <env-entry>
        <env-entry-name>foo/maximum</env-entry-name>
        <env-entry-type>java.lang.Integer</env-entry-type>
        <env-entry-value>10</env-entry-value>
    </env-entry>
    
    <resource-ref>
        <res-ref-name>myDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
    </resource-ref>

    <ejb-ref>
        <ejb-ref-name>ejb/myBean</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <remote>some.package.MyBeanInterface</remote>
    </ejb-ref>

or via annotations on the component class

@Resource(name="myDataSource", type=javax.sql.DataSource.class)
@EJB(name="ejb/myBean", beanInterface= some.package.MyBeanInterface.class)

Then we use these java:comp/env/xxx 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 interceptors.

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 this.

  1. Do we need the module scope in EJB module?
  2. Do we need to introduce the application scope?
  3. 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.

Related Topics >> J2EE      
Comments
Comments are listed in date ascending order (oldest first)

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n

RED EYE OWNZ - by Z4i0n
Syndicate content