Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:16:40+00:00 2026-05-22T20:16:40+00:00

Is there any situation still ( given that Java EE6 has java:global/, app/, module/

  • 0

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?

@EJB (name = "ejb/PlaceBid", beanInterface = PlaceBid.class)
public class ActionBazaarBidControllerServlet extends HttpServlet {

}

Looking up PlaceBid in the helper class used by ActionBazaarBidControllerServlet

PlaceBid placeBid = (PlaceBid)context.lookup("java:comp/env/ejb/PlaceBid");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:16:41+00:00Added an answer on May 22, 2026 at 8:16 pm

    The java:comp/env/ namespace is sometimes a little understood feature. This namespace corresponds to what is called the Enterprise Naming Context (ENC).

    It’s like a private “hashmap” associated with each component, with the entire web module being treated as one component and individual EJB beans each being components as well.

    You use this private namespace mostly for aliasing purposes. If you map something under “ejb/PlaceBid”, then all (helper) code can use “ejb/PlaceBid” and at one global location (the servlet in this case, but it could also be XML) you can determine what is exactly mapped to it. If all code went directly to java:global/... then there might be dozens of hardcoded dependencies to this name.

    So, you would use this if you need the extra redirection.


    Some other things to note:

    1.
    With the EJB SessionContext you can reference this namespace directly, as-in:

    PlaceBid placeBid = (PlaceBid)sessionContext.lookup("ejb/PlaceBid");
    

    Here “ejb/PlaceBid” is a relative name into the ENC.

    2.
    As mentioned, the ENC is private for each component. Different EJBs can have a given relative name mapped differently. context.lookup("java:comp/env/ejb/PlaceBid") can thus return something different depending on from which component you make the call.

    3.
    Historically, the ENC predated what we now call injection. In a way, when you specified a mapping in XML, you ‘injected’ something into the private “hashmap” associated with that component. The modern version injects into fields, constructors or properties (setters), but the old version injected into ‘keys’.

    Even in EJB3.1, the historical ‘injection’ mechanism is still active under the hood. If you perform a seemingly normal injection using @EJB on a field, then this also automatically creates an entry in the JNDI ENC. E.g.

    package test;
    
    @Stateless
    public class MyBean {
    
       @EJB
       private MyService myService;
    
    }
    

    In this case, whatever is injected into myService is also stored in the ENC under name java:comp/env/test.MyBean/myService. To complete the link with the @EJB annotation you used on the Servlet: you can optionally use the name attribute to specify the name under which the reference is stored in the ENC:

    @Stateless
    public class MyBean {
    
       @EJB(name = "ejb/PlaceBid")
       private MyService myService;
    
    }
    

    A little counter-intuitive, but in most cases the name attribute here is thus not something that points to a source where the object to be injected is taken from, but it’s used as a target in the ENC to inject into.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any free or commercial component written in .NET (no COM interop) that
Situation is that level of log4net is configured as 'Error' but there is some
Is there any easy way / library / external app to introduce Unit of
Are there any situations when you would use assertion instead of exceptions-handling inside domain
Is there any way to check whether a file is locked without using a
Is there any query which can return me the number of revisions made to
Is there any efficiency difference in an explicit vs implicit inner join? For example:
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
Is there any known way of listing the WMI classes and their properties available

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.