1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Cross origin error in spring boot does not recognize CrossOrigin() annotation

Discussão em 'Angular' iniciado por Name1 Name2, Outubro 3, 2024 às 15:03.

  1. Name1 Name2

    Name1 Name2 Guest

    I have Angular in apache2 for frontend and we are using spring boot, in spring boot, I have added @CrossOrigin(origins = “https://frontend.com”) annotation on a controller, and it keeps preventing me from communicating,

    `@RestController
    @CrossOrigin(origins = “https://frontend.com”)
    public class Department {

    @Autowired
    DepartmentService departmentService;

    @PostMapping(“/input”)
    public ResponseEntity<Message> createDepartment(@Valid @RequestBody DepartmentoDto dto) {
    return ResponseEntity.ok(departmentoService.save(dto));
    }`


    This is the error

    Request from another origin blocked: the policy of the same origin prevents reading the remote resource at https://backend/input (reason: missing CORS header 'Access-Control-Allow-Origin'). Status code: 403

    Object { headers: {...}, status: 0, statusText: Unknown Error, url: https://backend/input, ok: false, name: “HttpErrorResponse”, message: 'Http failure response for https://backend/iput 0 Unknown Error', error: error }


    This worked when both were in HTTP, but after switching to HTTPS.

    Attempted to test it by allowing all headers, but it did not work:

    @CrossOrigin(origins = “https://frontend.com”,allowedHeaders = “*”)

    Continue reading...

Compartilhe esta Página