Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use @EJB annotation returns null

 
R Jng
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,I am a .NET developer. In my free time, I am learning some Java technology. I am still new to Java. Right now, what confuses me is this @EJB annotation.
Guess I will use the code to explain.
These are my steps in Eclipse
1. Create a EJB project (say myEJB)



2.Create a client project to call EJB, so I create a dynamic web project (say myEJBCaller)
-Add myEJB to myEJBCaller
- Create a servlet,then call EJB method
This is my code


Well, this works fine using JNDI lookup. BUT if I switch to the EJB call using @EJB annotation, it never worked.
if I am doing like this, the @EJB will returns null

P.S Here, I never modified any xml file in either projects.


Can anyone tell me what's the problem when I use @EJB annotation?
Thank you in advance.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch and have fun learning Java!

Annotation based injection into web components (like servlets) was introduced in a specific version of Servlet spec (which is part of Java EE). So if injection has to be supported, the server expects that your web.xml use a specific XSD version. It should be 2.5 or higher. What does your web.xml look like?

On a different note, since you say you are learning Java, it might be a good idea to take a look at the coding conventions. For example, the convention for method names is to begin with lower case. So sayHello(String name) instead of SayHello(String name). There are some other useful conventions here http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html


 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!