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 523681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:29:15+00:00 2026-05-13T08:29:15+00:00

I tried several ways in the session bean, like: @Resource private SessionContext ctx; OR

  • 0

I tried several ways in the session bean, like:

@Resource
private SessionContext ctx;

OR

private SessionContext ctx;

@Resource
private void setSessionContext(SessionContext ctx) {
  this.sctx = ctx;
}

OR

InitialContext ic = new InitialContext();
SessionContext ctx = (SessionContext) ic.lookup("java:comp/env/sessionContext");

None of them worked, differnet exceptions occured in JBOSS.

I really get mad about it. Anyone could tell me what’s wrong. Thanks a lot!

  • 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-13T08:29:16+00:00Added an answer on May 13, 2026 at 8:29 am

    The two first solutions (field injection and setter method injection) look fine and should work.

    I have a doubt about the third one (the lookup approach) as you didn’t show the corresponding @Resource(name="sessionContext") annotation but it should work too if properly used.

    A fourth option would be to look up the standard name java:comp/EJBContext

    @Stateless
    public class HelloBean implements com.foo.ejb.HelloRemote {
      public void hello() {
        try {
          InitialContext ic = new InitialContext();
          SessionContext sctxLookup = 
              (SessionContext) ic.lookup("java:comp/EJBContext");
          System.out.println("look up EJBContext by standard name: " + sctxLookup);
        } catch (NamingException ex) {
          throw new IllegalStateException(ex);
        }
      }
    }
    

    These four approaches are all EJB 3 compliant and should definitely work with any Java EE 5 app server as reminded in 4 Ways to Get EJBContext in EJB 3. Please provide the full stack trace of the exception that you get if they don’t.

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

Sidebar

Related Questions

I've tried several ways to get this to render correctly. I want my logo
Can this code be shorten in some way? I've tried several ways to compact
I've tried several ways to open an OTB file (otb files is like dat
I've tried several ways to achieve this but here goes... I have the following
What's wrong with this? .serialize() returns nothing. I've tried several ways to do this,
I tried several ways to retrieve datetime2(3) equivalent from C# code but in vain.
I have tried several ways to login to a website through java. I have
I tried several ways to apply the .css and .js files to the view
I've tried several ways to update an object in my database. I've also read
I have tried several ways to cast a float to an int, what I

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.