can both "LocalBean" and "Remote" be annotated on one bean?

ejb, jakarta-ee, java

Solution

Yes, it is possible for a bean to expose multiple views (Remote business, Local business, no-interface).

The component can be the same - you just add another ways of accessing it.

Take a look at EJB 3.1 FR specification:

4.4.2.2 Session bean exposing multiple client views (p. 86).

package com.acme;

@Singleton(name="Shared")
@LocalBean
@Remote(com.acme.SharedRemote.class)
public class SharedBean { ... }

One note - I don't think the example you posted will work out-of-the-box. You're using `@Remote` and `@Local` without specifying the interface references. I don't think the container will now which interface is what. Either specify the `@Remote(clazz)` or annotate the interface itself as `@Remote`.

Problem

I know it might sound elementary, but i'm wondering the following singleton bean: ``` @Startup @Singleton @LocalBean public class MyServiceBean { public String sayHello() { return "Hello"; } } ``` Now i think "remote" clients might need use this bean, so I want to add a Remote interface to this bean: ``` @Remote public interface MyService { String sayHello(); } ``` Can I just make my bean implements the new remote interface? If "MyServiceBean" implements the "MyService" remote interface, it will become a bean with a "remote-interface-view" ... but after I searched the web, you all said that a bean with annotation "LocalBean" is a "no-interface-view". Is that able to work? or should I create a Local interface and remove the LocalBean annotation? deeper thoughts... if "remote-view", "local-view" and "no-interface-view" are 3 types of view which can all exist in one bean....? can i have a bean that implements all of them? ``` @Local @Remote @LocalBean public class Possible implements PosLoca, PosRemote {} ``` .... i'm really confused...

Original source