reactjsajaxspring-bootmicroservicescross-origin-read-blocking

Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type application/json


calling service from reactjs to spring boot. getting below error Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type application/json

react code:

fetch(URL, {method: 'GET',
            contentType: 'application/json',
            mode: 'no-cors'
          }).then (function (response) { return response.json()})
            .then(function (json) {debugger;console.log(json)})
            .catch(function (error) {debugger;console.log(error)});

spring code:

    @GetMapping(path="/user/{aid}", produces= {"application/json"})
    public Optional<User> getUser(@PathVariable int aid) {
        return userRepo.findById(aid);
    }

error message:

Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type application/json


Solution

  • You need to allow CORS from your spring code app. Hope this helps.Enabling Cross Origin Requests for a RESTful Web Service