Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Use @EJB annotation returns null

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic