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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:50:33+00:00 2026-06-15T23:50:33+00:00

I am learning Java EE and JSP. I have created an Enterprise Application project

  • 0

I am learning Java EE and JSP. I have created an Enterprise Application project in NetBeans.
I have the EJB project where all beans are and a WAR project where all web/client stuff is.
My problem is that the annotation @EJB does not instantiate my Bean in the WAR application. Can I use @EJB outside the EJB application?

In the EJB project, I have these files:
CustomerRemote.java

@Remote
public interface CustomerRemote {
    public Customer createCustomer();
    public Customer getCustomer(int customerId);
    public void removeCustomer();
}

CustomerBean.java

@Stateless
public class CustomerBean implements CustomerRemote {

    @PersistenceContext(unitName="testPU")
    private EntityManager entityManager;

    @Override
    public Customer createCustomer() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeCustomer() {        
    }

    @Override
    public Customer getCustomer(int customerId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

In the WAR project, I have a file that my JSP page uses to communicate with the EJB stuff. The problem is that the CustomerRemote object is never instantiated. @EJB annotation does not seem to work because customerRemote always is null. But when instantiating it with the lookup method, it works! So why does not @EJB work?

public class CustomerProxyBean {

@EJB
private CustomerRemote customerRemote;

public CustomerProxyBean() {        
//    try {
//        InitialContext context = new InitialContext();
//        customerRemote = (CustomerRemote)context.lookup("java:app/SimpleShop-ejb/CustomerBean");
//        
//    } catch (NamingException ex) {
//        Logger.getLogger(CustomerProxyBean.class.getName()).log(Level.SEVERE, null, ex);
//    }
}
  • 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-06-15T23:50:34+00:00Added an answer on June 15, 2026 at 11:50 pm

    @EJB annotation will work only in cases where your class is container-managed, that is EJB, servlet, JSP… In your case you put it into plain old Java object (POJO) so injection will not work, as you have experienced. Write your CustomerProxyBean as a stateless session bean, and you’ll see the change.

    Alternatively, if you want to avoid JNDI for some reason, you can use CDI and @Inject annotation to inject EJB and achieve wished behaviour, even in POJO:

    @Inject
    private CustomerRemote customerRemote;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a decent working web application (Java/Servlet/Jsp) that I would like to improve
I have started working on a Web java learning project. I am making a
I'm learning J2EE and migrating my ASP.NET project into Java. IN Asp.NET I have
I am just starting out learning Java, GAE etc. I have started a project
Other than learning java, spring, hibernate, servlets, jsp's, how to use eclipse/netbeans, databases like
I'm planning on learning Java, I have experience programming in other Object Oriented languages,
I am learning Java with Swing and I have some problems with using JTextField
I am learning Java and have been given these options: How can you implement
I've recently starting learning java web development and I want to learn/understand: What constitutes
I am learning Java and have a pretty basic problem. I am indexing some

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.