Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaEE 6: @EJB(beanInterface="")

Could someone help me understand the use of beanInterface parameter of @EJB annotation in JavaEE 6?

I have a situation in which I have an EJB and I want it to be accessed locally and remotely as well.

I have a MyBaseInterface and then both MyEJBLocalInterface and MyEJBRemoteInterface extending MyBaseInterface. Now I have MyEJB which is implementing both MyEJBLocalInterface and MyEJBRemoteInterface.

Now I have a situation in which I want only to access MyEJB locally.

Could I achieve the same with the following?

@EJB(beanInterface=MyEJBLocalInterface.class)
private MyBaseInterface instanceOfLocallyAccessedMyEJB;

Could someone help me understand the use of beanInterface parameter of @EJB attribute?

Thanks.

like image 959
skip Avatar asked Oct 05 '11 19:10

skip


People also ask

What is the use of @EJB annotation?

Annotations were introduced in Java 5.0. The purpose of having annotations is to attach additional information in the class or a meta-data of a class within its source code. In EJB 3.0, annotations are used to describe configuration meta-data in EJB classes.

What is @local annotation in ejb?

javax.ejb The Local annotation is applied to the session bean class or local business interface to designate a local interface of the bean. When used on the bean class, declares the local business interface(s) for a session bean. When used on an interface, designates that interface as a local business interface.

What is ejb in html?

The ejb-name of the Enterprise Java Bean to which this reference is mapped. java.lang.String. description. A string describing the bean.

What is ejb in Java with example?

EJB (Enterprise Java Bean) is used to develop scalable, robust and secured enterprise applications in java. Unlike RMI, middleware services such as security, transaction management etc. are provided by EJB Container to all EJB applications. The current version of EJB is EJB 3.2.


1 Answers

the beanInterface attribute of the @EJB annotation is used for different purposes depending on the EJB version you are using:

  • In EJB 3.X you can use it to specify whether you want to use the remote of local reference of the EJB you are referring to, which is your case.
  • In EJB 2.X it is used to specify the Home/LocalHome interface of the session/entity bean

To sum up, yes. You should be able to use it to inject the desired interface.

This might not be supported in older versions of JBoss though.

like image 66
Gonzalo Garcia Lasurtegui Avatar answered Oct 04 '22 21:10

Gonzalo Garcia Lasurtegui