How to use CDI in WebService?

0

I am trying to inject a @Injection ed bean into a WebService , but the bean is always null.

Dependency injection is working on my project. When I use @Injection inside a Managebean for a jsp page everything is ok.

@WebService
public class listaUsuariosWS {
    @Inject private LoginService loginService;
    public String getName(){
        List<Usuario> lst = loginService.listarTodos();
        Usuario u = lst.get(1);
        String nome = u.getNomeUsuario();
        return nome;
    }
}

Any idea what it could be?

    
asked by anonymous 15.03.2017 / 20:30

1 answer

0

The class ListWSUser has to be managed by the container so that the Bean is injected. Try to give it a scope using EJB:

@Stateless

or CDI:

@RequestScope

Note: I do not know if @RequestScope works in @WebService, I just indicated it for example.

    
13.04.2017 / 16:05