Java EE 6 WebService和CDI注入 [英] Java EE 6 WebService and CDI injection
问题描述
这是我从Java EE 5迁移中得到的一个澄清问题。我目前正在开发打包在WAR文件中的Java EE 6网络服务,我想知道是否可以在其上使用CDI。我看过一些使用 @Stateless
注释的示例,据我所知,在WAR中是不可能做到的。
This is a clarification question I've got from a Java EE 5 migration. I'm currently developing a Java EE 6 web service packed in a WAR file, and I would like to know if it's possible to use CDI on it. I've seen some examples using the @Stateless
annotation, which it's not possible to do in a WAR (as far as I know).
当前实现:
@WebService
public class MyService{
@Inject
HelloTeller teller:
@WebMethod
public String sayHello(){
teller.sayHello();
}
}
注意:另一种方法是创建 ejbModule 专门用于此Web服务。
Note: The other approach would be to create an ejbModule specifically for this web-service.
推荐答案
在EE6中,您应该能够使用SLSB作为战争中的JAX-WS端点。您可以从CDI注入EJB,请求作用域和应用程序作用域的Bean。
In EE6, you should be able to use a SLSB as JAX-WS endpoint in a war. You can inject EJBs, request scoped and application scoped beans from CDI.
这篇关于Java EE 6 WebService和CDI注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!