title: CORS in spring boot is not working - getting empty response
body: <p>I am using Spring Boot (Tomcat + Java) for my backend app and React for my front end.
  I am trying to access "<a href="http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03" rel="nofollow noreferrer">http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03</a>" from "<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>".</p>
  
  <p>I added @CrossOrigin(origins = "*") both at the controller level and at endpoint level. I am getting empty result.
  I added @CrossOrigin both at the controller level and at endpoint level. I am getting empty result.</p>
  
  <p>If I remove the @CrossOrigin annotation, I am getting the Cors error. That means the annotation is necessary. The error is "Access to fetch at '<a href="http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03" rel="nofollow noreferrer">http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03</a>' from origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."</p>
  
  <p>If I copy paste the link in the browser directly, it is working and returns JSON.
  If I call "<a href="https://cdn.rawgit.com/rrag/react-stockcharts/master/docs/data/MSFT.tsv" rel="nofollow noreferrer">https://cdn.rawgit.com/rrag/react-stockcharts/master/docs/data/MSFT.tsv</a>" it is also returning result.</p>
  
  <p>To avoid typos, I did console.log and I am pasting these from console.log.</p>
  
  <p>I am using fetch for 'get'ting.</p>
  
  <p>[Edit 1]
  I am looking at the tomcat logs and will update it shortly.</p>
  
  <p>[Edit 2]
  TL;DR
  It's not a CORS problem.</p>
  
  <p>Full description:
  1. The response for "<a href="http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03" rel="nofollow noreferrer">http://localhost:8080/vr-backend-0.0.1-SNAPSHOT/stockdata/NIFTY19DECFUT?from=2019-12-03&amp;to=2019-12-03</a>" was 200.</p>
  
  <ol start="2">
  <li><p>I logged in the spring boot app and looked at the tomcat logs. It reaches the controller method and I get the proper results from DB. When I send the response back, I am getting empty result in the browser. As mentioned before, if I hit the url directly, I am getting proper results.</p></li>
  <li><p>It is not a preflight OPTIONS request.</p></li>
  <li><p>So it can be concluded that it is not a CORS problem. @CrossOrigin annotation works</p></li>
  </ol>
  
  <p>I looked at the logs after posting the question. So this question can be closed as it is incorrect. If I am not able to fix the empty response problem, I will post a separate question as this question title is misleading.</p>
  
  <p>Thank you all for the response.</p>