Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@LocalBean and @Remote for the same session bean

 
Nandhini Sridharan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going through Frits notes on EJB 3.1. In page 2-11, there is a code example

@Stateless
@Remote(EchoBeanRemote.class)
@LocalBean
public class EchoBean implements EchoBeanRemote {
}

With the above code, The methods declared in EchoBeanRemote interface would be exposed to remote clients. But, by adding @LocalBean, does this mean that all the public methods of the bean (irrespective of the methods declared in remote interface) are exposed to local clients?

Also for @Local and @LocalBean, The client and the bean implementation should be within the same EAR. Please correct me if I am wrong.

Thanks.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the above code, The methods declared in EchoBeanRemote interface would be exposed to remote clients. But, by adding @LocalBean, does this mean that all the public methods of the bean (irrespective of the methods declared in remote interface) are exposed to local clients?

Yes, through the no-interface client view.

Also for @Local and @LocalBean, The client and the bean implementation should be within the same EAR. Please correct me if I am wrong.

Yes, that is correct.

Note however that the definition of a local client (Local view or No-interface view) means that the client is collocated in the same JVM which doesn't necessarily mean that they have to be packaged in the same EAR. However the EJB specifications further specify that access to an enterprise bean through the local client view is only required to be supported for local clients packaged within the same application.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a good example from Ivan's notes: http://www.coderanch.com/t/647080/java-EJB-SCBCD/certification/lookup-remote-bean
I forgot to annotation the interface with @Remote, so by default it is @Local.
I package the servlet client in .war ,EJB in .jar and package both .war and .jar in the same .ear, the servlet client can lookup the EJB.
But if the .war and .jar are not in the same .ear or in different .ear files, the servlet client cannot lookup the EJB. It is because the EJB is exposed as a @Local view.
 
Nandhini Sridharan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Himai and Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic