Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to ejb 3 session bean from struts 2 ActionSupport

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get a reference to an ejb 3 local session bean from a struts 2 ActionSupport subclass?

E.g. is injection possible?

I did try to inject but got null.

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In theory, you're supposed to be able to use the @EJB annotation in a web client. In practice, most web containers don't support it. The best way I know of to get an EJB3 reference that works fairly consistently is:
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like the other variations I tried with lookups, it also threw exception on that statement.



Just to note that when using servlet without struts, the annotation works. But now I need to use the session bean inside struts ActionSupport.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest reading this link from the WAS 6.1 Infocenter.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Merrill Higginson:
In theory, you're supposed to be able to use the @EJB annotation in a web client. In practice, most web containers don't support it. The best way I know of to get an EJB3 reference that works fairly consistently is:


Thank you for the link. It helped clear things up.

And thanks, the code you gave above worked! (after I changed @Local to @Remote in session bean.

For why WAS wants it like that is another mystery; but good enough for now for my purpose.

The injection @EJB still didnt work; but anyway I have that code above to get the bean.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you got it working.

Just for the record, according to the link I gave you, it should still be possible to use the local interface if you append "ejblocal:" to the beginning of the lookup name.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I will try that out when I have time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic