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

  • Home
  • SEARCH
  • 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 803205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:43:21+00:00 2026-05-14T23:43:21+00:00

I’ve got an app that is trying to use @EJB annotation to inject remote

  • 0

I’ve got an app that is trying to use @EJB annotation to inject remote references to EJBs in my ejb.jar file. I’m getting inconsistent results. In one case, I have a listener in web.xml that gets called and apparently has the EJB injected correctly, since I can see it connecting to the EJB and calling methods on it. In another class (a struts2 action) I get NPE when it tries to access the EJB reference. As far as I can tell, they’re identical calls, in Java classes that live in the same .war file.

As a work around, I added code in the constructor to lookup the EJBs by their global JNDI names, and it works fine. I just can’t figure out why one @EJB works and not another.

  • 1 1 Answer
  • 1 View
  • 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-14T23:43:22+00:00Added an answer on May 14, 2026 at 11:43 pm

    How do you inject EJBs in Struts 2 actions? Are you using CDI? Are you using the Struts2 CDI plugin?

    Update: The problem is that the container is not creating the Struts objects, Struts is, so the container doesn’t get the opportunity to inject anything. You’ll have to use the mentioned plugin for CDI to enable injection in your actions.

    If you want to give it a try, get Struts 2 sources:

    svn co http://svn.apache.org/repos/asf/struts/struts2/trunk/ struts2
    

    Then cd into the struts2 directory and run the following command (this will compile the required modules for the struts-cdi-plugin)

    mvn install -pl plugins -am
    

    Then get the sources of the cdi-plugin:

    svn co https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-plugin/
    

    And compile it:

    mvn install
    

    Now, with the following dependencies in my pom.xml:

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-cdi-plugin</artifactId>
        <version>2.2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>javassist</groupId>
      <artifactId>javassist</artifactId>
      <version>3.8.0.GA</version>
    </dependency>
    

    I was able to get an EJB injected in an Action:

    public class HelloWorld extends ActionSupport {
    
        @Inject
        HelloEJB helloEjb;
    
        @Override
        public String execute() throws Exception {
            setMessage(helloEjb.getMessage());
            return SUCCESS;
        }
    
        private String message;
    
        public void setMessage(String message) {
            this.message = message;
        }
    
        public String getMessage() {
            return message;
        }
    
    }
    

    See https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-example/ for an example.

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

Sidebar

Related Questions

No related questions found

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.