How to call a method on one @Stateless bean from another @Stateless bean

I created a non-bean session in Java. Now I want to call a method of another session without a bean state. Some things are missing in my code. The usual method call method is not suitable here. Being called on another session with no state, the bean retrieves data from the Internet.

Similarly, how to call a method from the @Stateless bean of a simple Java class. I am creating a REST web service using Java, and for some reason I cannot call methods that are in a simple Java class from @Stateless beans. Greetings

+4
source share
2 answers

Just enter it @EJB

 @Stateless public class StatelessBean1 { @EJB private StatelessBean2 bean; } 
+5
source

There is nothing special about invoking methods on a session without a bean state. You use the same syntax as for any other type of bean.

As Bojo pointed out, the only thing that is especially important in EJB is that you cannot create an instance using the new operator. You need to enter an instance or, alternatively, search in JNDI. After that, the usual Java rules apply.

This really doesn’t need to be explained, but, of course, calling the method on a session without a bean state called a 'bean':

 bean.someMethod(someArgument); 
0
source

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


All Articles