Tengo el siguiente metodo en mi back con spring boot
@CrossOrigin(origins="http://localhost:4200")
@RestController
@RequestMapping("/consultarValores")
public class Valores {
@Autowired
private ValoresService valoresService;
@GetMapping
public List<ValotesDto> consultarValoresParam(@RequestParam (value="fechInicio") int fechInicio, @RequestParam (value="fechFinal") int fechFinal){
return valoresService.listarValore(fechInicio, fechFinal);
}
}
y agregue esta clase para tratar de solucionar el problema que menciono, pero aun asi no me funciona
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/").allowedOrigins("http://localhost:4200")
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true);
}
}
y este es mi service.ts de Angular en el cual hago la peticion al backend
export class ConsultarValoresService {
constructor(private http: HttpClient) { }
Url = 'http://localhost:8080/consultarValores';
consultarValores(fechaInicial:any, fechaFinal:any){
return this.http.get<ValoresDto[]>(this.Url+"/"+fechaInicial+"/"+fechaFinal);
}
}
y obtengo este error
from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
modique esta linea de la siguiente manera
registry.addMapping("/**")
y al ejecutarlo asi, me sale el error 404
zone-evergreen.js:2863 GET http://localhost:8080/consultarValores/20210419/20210423 404
qué esta mal? o que debo agregar para que me deje hacer la peticion? debo agregar algo adicional de configuracion?