简体   繁体   English

如何从另一个@Stateless bean调用一个@Stateless bean上的方法

[英]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.

相关问题 如何从另一个包中的第二个@Stateless bean调用一个@Stateless bean的方法 - How to invoke method on one @Stateless bean from second @Stateless bean in another package 如果业务接口中未声明无状态Bean方法,该如何调用 - How to invoke a stateless bean method if it is not declared in business interface 如果未在实现业务逻辑的接口中声明,如何调用无状态 bean 方法 - How to invoke a stateless bean method if it is not declared in interface implementing the business logic 将无状态(Webservice)Bean注入另一个Bean - Inject Stateless (Webservice)Bean into another Bean 从WebSphere Administration Console 7.0或WebSphere Application Server的utils调用EJB无状态会话Bean方法 - Invoke EJB Stateless Session Bean method from WebSphere Administration console 7.0 or with WebSphere Application Server's utils 来自无状态会话bean的FileIO - FileIO from an stateless session bean 从无状态Bean返回有状态Java Bean? - Returning a Stateful Java Bean from a Stateless Bean? 如何将侦听器添加到无状态Bean - How to add listener to stateless bean 我们可以从静态方法访问/调用无状态会话Bean吗? - Can we access/call Stateless Session Bean from Static method? 为什么我通过从 bean 调用 @Stateless 方法得到 TransactionRequiredException? - Why am I getting TransactionRequiredException by invoking a @Stateless method from a bean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM