File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Considering Injection i EJB 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Considering Injection i EJB 3.0" Watch "Considering Injection i EJB 3.0" New topic
Author

Considering Injection i EJB 3.0

ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello,

My environment is:
Using JBoss ver. 4.2.1 and %JAVA_HOME% IS 'C:\Program Files\Java\jdk1.5.0_12', my JRE is 'java version "1.6.0_02" ' which should not cause any harm.

Reading Debu Panda's article on DI from 2006 on ONJava.
Still, having problem using the @EJB.
The example in Pandas article ( page 4 ) is like this:

He never tells where the ProcessManager is coming from, it must be from a ejb-jar.xml ( or another DD ) - but how is the syntax ?

Another example:
From O'Reillys workbook (Enterprise Javabeans 3.0, 5th edition ) there is an example of a Stateless 'TravelagentBean' that is using 'ProcessPaymentBean' which implements both a Local and a Remote interface ( ch. 11_5 ).
The 'TravelAgentBean' is using 'ProcessPaymentBean', and the code within the 'TravelAgentBean' is like this:

and the ejb-jar.xml is like this:

But the syntax is not correct.
I am getting the following error:


And finally:


is there an obvious answer here or am I totally missing the point ?

regards, i

ps.
My ejb-jar.xml starts with these lines:

Is this the correct information to my JBoss ?
ds.

[ October 12, 2007: Message edited by: ing erl ]

[ October 12, 2007: Message edited by: ing erl ]

[ October 12, 2007: Message edited by: ing erl ]

[ October 12, 2007: Message edited by: ing erl ]
[ October 12, 2007: Message edited by: ing erl ]
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
ing,

ProcessManager is an interface that contains business methods. If you have @Local annotation on ProcessManager then "ProcessManager" will be registered as the jndi name. It is all done through injections... no more ejb-jar.xml file required.

In your second case...

Is that your complete ejb-jar.xml file? If yes then it is not complete. In this sample you do not need to use ejb-jar.xml... just make sure that PaymentProcessLocal interface has @local annotation.

The same argument applies for TravelAgentBean.


Shailesh Kini.
ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello Shailesh Kini!!!

You saved me here, thank you so much.
Well, one is puzzled these days; I bought 3 pair of books regarding EJB 3.0.
Everyone of them has so many errors that you loose faith in the end.

The O'Reilly where the example is from, here is their ejb-jar.xml file:


So, from this example - how am I to know that this is the wrong way to do things ?
As you said, I had it all from the start with the '@Local' annotation.
My ejb-jar.xml is only these few lines:


And it is just for the sake of testing.

So I am very greatful for your help.
Are there any books out the covering EJB 3.0 for a newcomer in the Enterprise JavaBeans world in the sence that I am not coming from EJB 2.1, but from J2SE ? A book where nothing is taken for granted?

Going to follow this up by looking at JMS and Transactions, within EJB 3.0.
If you have any tips regarding the subject, you are welcome.

regards, i
[ October 12, 2007: Message edited by: ing erl ]
ing erl
Greenhorn

Joined: Jan 27, 2006
Posts: 15
Hello,

Using Local interfaces with the annotation @EJB.
Is that only possible to use from other Enterprise Javabeans.
I am not able to use the @EJB from within a servlet
though the servlet is running in the same JVM as the EJB ?
When using an EJB from within a Servlet I must always use 'lookup' ?

regards, i
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hello ing,

I have read very good reviews about Pro EJB3 but haven't read it myself. I think you should give it a try.

You should be able to use @EJB from within a servlet. Servlet 2.5 spec does not require you to perform a lookup. It will resolve @EJB annotation for you.

These link might help.
web page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Considering Injection i EJB 3.0
 
Similar Threads
OpenEJB, DI Overriding annotation with deployment descriptor
EJB 2.x and EJB 3 coexisting
ejb name (5.0)
EJB3 - NullPointerException with @EJB Injection
Problems with EJB3.0... (continued)