Java EE 6 WebService and CDI injection

2019-05-30 07:57发布

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).

Current implementation:

@WebService
public class MyService{

    @Inject 
    HelloTeller teller:

    @WebMethod
    public String sayHello(){
        teller.sayHello();
    }
}

Note: The other approach would be to create an ejbModule specifically for this web-service.

1条回答
Anthone
2楼-- · 2019-05-30 08:04

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.

查看更多
登录 后发表回答