So far, I almost always worked with no-interface EJBs and have a slight understanding about the need of @Local annotation. Consider this example:
public interface MyBeanIntf { void doStuff(); }
@Stateless
public class MyBean implements MyBeanIntf { public void doStuff(){ } }
Should the MyBeanIntf
be marked as @Local
? I don't see any benefit from that, because even when I don't annotate it as @Local
, I still can use DI to properly inject it into UI Controller:
@Named
@SessionScoped
public class TestController implements Serializable {
// injection works perfectly, even when MyBeanIntf is not marked as @Local
@Inject
private MyBeanIntf myBean;
// or even like this:
// @EJB
// private MyBeanIntf myBean;
}
Let's make it more complex:
public interface MyBeanIntf { void doStuff(); }
public class MySuperBean implements MyBeanIntf { public void doStuff() { } }
@Stateless
public class MyBean extends MySuperBean { }
Is MyBean
now considered a valid Local EJB
bean? I have some doubts because it implements the interface indirectly.