My @Inject not work with my web service (@Path), but work with @WebServlet, why?
my web service
@Path("/autenticacao")
public class UsuarioService {
@Inject
private UsuarioRepository usuarioRepository;
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response autentica(@FormParam(value = "cpf") String cpf, @FormParam(value = "senha") String senha){
Usuario usuario = usuarioRepository.getUsuarioByCPFSenha(cpf, senha);
return Response.status(200).entity(usuario).build();
}
}
Definition of the UsuarioRepository
interface
public interface UsuarioRepository {
public Usuario getUsuarioByCPFSenha(String cpf, String senha);
}
my implementation of UsuarioRepository
interface
public class UsuarioRepositoryImp implements UsuarioRepository {
@Inject
private Connection connection;
@Override
public Usuario getUsuarioByCPFSenha(String cpf, String senha) {
String SQL = "SELECT se01_cpf, se01_senha FROM se01_usuario WHERE replace(replace(se01_cpf,'.',''),'-','') = ? AND se01_senha = ?";
Usuario usuario = null;
try {
PreparedStatement stmt = connection.prepareStatement(SQL);
stmt.setString(1, cpf);
stmt.setString(2, senha);
ResultSet set = stmt.executeQuery();
while(set.next()){
String c = set.getString("se01_cpf");
String s = set.getString("se01_senha");
usuario = new Usuario(c, s);
}
set.close();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return usuario;
}
}
my field usuarioRepository
is null after my requests, any idea?