"details": "Error id ac88c73a-a1ad-4f4d-b454-497637b871ae-1, java.lang.RuntimeException: Error injecting br.com.alura.service.http.SituacaoCadastralHttpService br.com.alura.service.http.AgenciaService.situacaoCadastralHttpService", "decorate": "Exception in AgenciaController.java:20\n\t 18 @POST\n\t 19 public RestResponse cadastrar(Agencia agencia, @Context UriInfo uriInfo) {\n\t-> 20 this.agenciaService.cadastrar(agencia);\n\t 21 return RestResponse.created(uriInfo.getAbsolutePath());\n\t 22 }",
package br.com.alura.service.http;
import br.com.alura.domain.http.AgenciaHttp;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@Path("/situacao-cadastral")
@RegisterRestClient(configKey = "situacao-cadastral-api")
public interface SituacaoCadastralHttpService {
@GET
AgenciaHttp buscarPorCnpj( String cnpj);
}
package br.com.alura.service.http;
import br.com.alura.domain.Agencia;
import br.com.alura.domain.http.SituacaoCadastral;
import br.com.alura.exceptions.AgenviaNaoAtivaOuNaoEncontradaException;
import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class AgenciaService {
@RestClient
private SituacaoCadastralHttpService situacaoCadastralHttpService;
private List<Agencia> agencias = new ArrayList<>();
public void cadastrar(Agencia agencia) {
var agenciaHttp = situacaoCadastralHttpService.buscarPorCnpj(agencia.getCnpj());
if (agenciaHttp == null || agenciaHttp.getSituacaoCadastral().equals(SituacaoCadastral.INATIVO)) {
throw new AgenviaNaoAtivaOuNaoEncontradaException();
}
agencias.add(agencia);
}
public Agencia buscarPorId(Integer id) {
return agencias.stream()
.filter(agencia -> agencia.getId().equals(id))
.toList()
.getFirst();
}
public void deletar(Integer id) {
agencias.removeIf(agencia -> agencia.getId().equals(id));
}
public void alterar(Agencia agencia) {
deletar(agencia.getId());
cadastrar(agencia);
}
}
package br.com.alura.controller;
import br.com.alura.domain.Agencia;
import br.com.alura.service.http.AgenciaService;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.resteasy.reactive.RestResponse;
@Path("/agencias")
public class AgenciaController {
private AgenciaService agenciaService;
AgenciaController(AgenciaService agenciaService) {
this.agenciaService = agenciaService;
}
@POST
public RestResponse<Void> cadastrar(Agencia agencia, @Context UriInfo uriInfo) {
this.agenciaService.cadastrar(agencia);
return RestResponse.created(uriInfo.getAbsolutePath());
}
@GET
@Path("{id}")
public RestResponse<Agencia> buscarPorId(Integer id) {
var agencia = this.agenciaService.buscarPorId(id);
return RestResponse.ok(agencia);
}
@DELETE
@Path("{id}")
public RestResponse<Void> deletar(Integer id) {
this.agenciaService.deletar(id);
return RestResponse.ok();
}
@PUT
public RestResponse<Void> alterar(Agencia agencia) {
this.agenciaService.alterar(agencia);
return RestResponse.ok();
}
}
application.properties: quarkus-rest-client.situacao-cadastral-api.url=http://localhost:8181