Jndi binding for local and remote stateless bean

I am trying to implement stateless EJB3 with remote and local interfaces, the problem is that the local call is called on another remote EJB with @EJB annotation, but it returns null or ClassCastException ( java.lang.ClassCastException: com.sun.proxy.$Proxy58 cannot be cast ).

To do a server search to get local stateless, I have to put 2 JNDI names for stateless, otherwise it will give me the remote.

 @Stateless(mappedName=IRemoteInterface.JNDI_NAME, description="...") @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @Interceptors({GenericInvocationHandler.class}) @Remote(IRemoteInterface.class) @Local(ILocalInterface.class) public class MystatelessBean extends AbstractBasicBean implements IRemoteInterface, ILocalInterface { ... } @Stateless(mappedName=IRouting.JNDI_NAME, description="gives access to other services") @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @Interceptors({GenericInvocationHandler.class}) @Remote(IRouting.class) public class RoutingServiceBean extends AbstractBasicBean implements IRouting { @EJB public ILocalInterface iLocalInterface; } 

Actually, when I use @EJB , I get NPE , and when I use @EJB(beanName=IRemoteInterface.JNDI_NAME) , I get a ClassCastException , which is the correct JNDI name of the remote interface.

I am looking for something like @LocalBinding and @RemoteBinding in JBoss.

Maybe something is missing for me?

+4
source share
2 answers
  • If you are using EJB3.0, you can use @Localbinding / @Remotebinding in JBoss. If you are using EJB 3.1, JNDI bindings are standardized (called JNDI portable global names).

  • name annotation attribute @Stateless / @Stateful defines the name of the bean. By default, this is an unqualified class name.

  • mappedName annotation attribute @Stateless / @Stateful used to map the bean to the JNDI name. If you provide this attribute, you need to provide the mappedName attribute of the mappedName annotation in order to reference the bean. In terms of display:

     @Stateless(name="Bar") => @EJB(beanName="Bar") @Stateless(mappedName="Foo") => @EJB(mappedName="Foo") 

In your example, try using:

 public class RoutingServiceBean { ... @EJB(mappedName=IRemoteInterface.JNDI_NAME) public ILocalInterface iLocalInterface; } 
+2
source

If you use JBOSS, you can specify the JNDI name of both the local and remote interface with annotations.

 @Stateless(mappedName=IRemoteInterface.JNDI_NAME, description="...") @LocalBinding(jndiBinding = ILocalInterface.JNDI_NAME) @Local(ILocalInterface.class) @Remote(IRemoteInterface.class) public class MystatelessBean extends AbstractBasicBean implements IRemoteInterface, ILocalInterface{ ... } 

OR

 @Stateless() @LocalBinding(jndiBinding = ILocalInterface.JNDI_NAME) @RemoteBinding(jndiBinding = IRemoteInterface.JNDI_NAME) @Local(ILocalInterface.class) @Remote(IRemoteInterface.class) public class MystatelessBean extends AbstractBasicBean implements IRemoteInterface, ILocalInterface{ ... } 

Note that the name of the remote JNDI can be determined using the Stateless or RemoteBinding annotation. The RemoteBinding and LocalBinding annotations are JBOSS specific and can be found in jboss-ejb3-ext-api.jar.

0
source

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


All Articles