7

Can an EJB bean implement multiple user defined interfaces, except business interfaces (@Local, @Remote) or No-Interface view (@LocalBean)?

For example define two interfaces UserInterface1, UserInterface2, with no annotation.

Is this legal to implement:

@Stateless
public class MyBean implements UserInterface1, UserInterface2 { ...

Then I have another confusion:

@Stateless
public class MyBean implements Runnable { ...
//inside I won't try to manage thread
}

Is this legal or illegal, I found that glassfish support this situation.

user1684651
  • 390
  • 1
  • 8
  • 21

1 Answers1

6

The given example is illegal, but nevertheless accepted by quite some implementations (application servers).

David Blevins started a thread about this on the EJB mailing list a while ago.

EJB 3.2 will make the rules more clear for this topic. See What's new in EJB 3.2 ? - Java EE 7 chugging along! (look for section Simplified the rules to define all local/remote views of the bean)

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • what if I just implement one interface (still without any annotation)? That interface could be user defined or interface from some java packages(for example java.lang.) is this implementation illegal? – user1684651 Dec 21 '12 at 11:01
  • 1 interface seems to be legal without using any annotations. See http://docs.oracle.com/javaee/6/api/javax/ejb/Local.html – Arjan Tijms Dec 21 '12 at 12:02
  • 3
    The answer is good, though it doesn't answer the topic question, to which I would respond, "yes, an EJB can implement multiple interfaces, but in that case, you must explicitly specify which interfaces are business interfaces using `@Local` or ejb-jar.xml". – Brett Kail Dec 21 '12 at 17:07
  • @bkail the topic title says "multiple interfaces", but the post opens with asking for multiple interfaces, **except business interfaces**. Unfortunately the situation with mixing (multiple) business interfaces and (multiple) regular interfaces is not that clear. – Arjan Tijms Dec 21 '12 at 22:19
  • Even considering David's post, the semantics seem quite clear when (non-empty) `@Local` is specified on the bean class. Anyway, if OP is satisfied, that's all that matters :-). – Brett Kail Dec 22 '12 at 00:24