I understand the difference between local view, remote view and no-interface view. I just don't understand what is the difference between "no view" (no annotation) and no-interface view. And also why should I annotate my interface with @Local
? What if I don't annotate the interface in at all, is there a difference?
Java – EJB 3.1 @LocalBean vs no annotation
ejbjakarta-eejava
Related Question
- Java – the difference between JDK and JRE
- Java – Difference between HashMap, LinkedHashMap and TreeMap
- Java – a JavaBean exactly
- Java – Which @NotNull Java annotation should I use
- Java – How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
- Java – Why is processing a sorted array faster than processing an unsorted array
- Java – difference between CrudRepository and JpaRepository interfaces in Spring Data JPA
- Java – the difference between canonical name, simple name and class name in Java Class
Best Solution
The rules are (from memory):
@LocalBean
annotation -> bean has a no-interface view@Local
annotation -> bean has a local view@Remote
annotation -> bean has a remote viewSo, using
@LocalBean
and using no annotation at all are both ways of getting a no-interface view. If you just want a no-interface view, then the simplest thing is not to annotate. Provided you're not also implementing any interfaces.Part of the reason
@LocalBean
exists to add a no-interface view to a bean which also has an interface view. I imagine the scenario uppermost in the spec authors' minds was one where you have a bean like:Where you would want to expose both methods locally, but only the coarser-grained
getPreferences()
remotely. You can do that by declaring a remote interface with just that method, then just slapping@LocalBean
on the bean class. Without it, you'd have to write a pointless local interface just to expose both methods locally.Or, to look at it another way, the
@LocalBean
exists because there is such a thing as a no-interface view, and the no-annotation option exists as a handy shortcut.