开发者

How to invoke method on one @Stateless bean from another @Stateless bean

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.

开发者_JS百科

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


Just inject it with @EJB

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜