[英]How to invoke method on one @Stateless bean from another @Stateless bean
I have created stateless session bean in Java. 我在Java中创建了无状态会话bean。 Now I want to invoke a method of another stateless session bean.
现在我想调用另一个无状态会话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.
在另一个无状态会话bean中调用方法从Internet检索数据。
Likewise, how to invoke a method from @Stateless bean of a simple Java class. 同样,如何从简单Java类的@Stateless bean调用方法。 I build a REST web service with Java and somehow I can't invoke methods being at simple Java class from @Stateless beans.
我用Java构建了一个REST Web服务,不知何故我无法从@Stateless bean调用简单Java类的方法。 Cheers
干杯
Just inject it with @EJB
只需注入
@EJB
@Stateless
public class StatelessBean1 {
@EJB
private StatelessBean2 bean;
}
There's nothing special about invoking methods on a stateless session bean. 在无状态会话bean上调用方法没什么特别之处。 You use the exact same syntax as with every other kind of bean.
您使用与每种其他类型的bean完全相同的语法。
As Bozho indicated, the only thing special about EJBs is that you can't construct an instance using the new operator. 正如Bozho指出的那样,EJB的唯一特殊之处在于你不能使用new运算符构造实例。 You need to inject an instance or alternatively do a JNDI lookup.
您需要注入实例或者执行JNDI查找。 After that, the normal Java rules apply.
之后,适用常规Java规则。
It really shouldn't need to be explained but to be sure, calling a method on a stateless session bean called 'bean': 它实际上不需要解释,但可以肯定的是,在名为'bean'的无状态会话bean上调用方法:
bean.someMethod(someArgument);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.