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…
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).
One note – I don’t think the example you posted will work out-of-the-box. You’re using
@Remoteand@Localwithout 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.