Is it possible to annotate "LocalBean" and "Remote" on the same bean?

I know this may seem elementary, but I'm interested in the following singleton bean:

@Startup @Singleton @LocalBean public class MyServiceBean { public String sayHello() { return "Hello"; } } 

Now I think that โ€œremoteโ€ clients may need to 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 implemented a new remote interface?

If "MyServiceBean" implements the remote interface "MyService", it will become a bean with a "remote view" ... but after I searched the Internet, you all said that the bean with the annotation "LocalBean" is a "view without interface "

Could this 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 views that can 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 ...

+4
source share
1 answer

Yes, it is possible for a bean to display multiple views (remote business, local business, no interface).

A component can be the same - you just add other ways to access it.

Take a look at the EJB 3.1 FR specification:

4.4.2.2 A bean session displaying several customer presentations (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 use @Remote and @Local without any interface references. I donโ€™t think the container will now be which interface. Either specify @Remote(clazz) , or annotate the interface itself as @Remote .

+3
source

Source: https://habr.com/ru/post/1446165/


All Articles