4
votes

I have created stateless session bean in Java. Now I want to invoke a method of another stateless session bean. Some things are missing in my code. Usual way of invoking method does not fit here. Being invoked method at another stateless session bean retrieves data from the Internet.

Likewise, how to invoke a method from @Stateless bean of a simple Java class. I build a REST web service with Java and somehow I can't invoke methods being at simple Java class from @Stateless beans. Cheers

2
Being invoked method at another stateless session bean retrieves data from the Internet. What does this even mean?Arjan Tijms

2 Answers

5
votes

Just inject it with @EJB

@Stateless
public class StatelessBean1 {
    @EJB
    private StatelessBean2 bean;
}
0
votes

There's nothing special about invoking methods on a stateless session bean. You use the exact same syntax as with every other kind of bean.

As Bozho indicated, the only thing special about EJBs is that you can't construct an instance using the new operator. You need to inject an instance or alternatively do a JNDI lookup. After that, the normal Java rules apply.

It really shouldn't need to be explained but to be sure, calling a method on a stateless session bean called 'bean':

bean.someMethod(someArgument);