HTTP Get request from angular to spring backend being blocked by CORS policy : <p>I have a @RestController in my java spring backend:</p>

<pre><code>@GetMapping(value = "/getItems")
public List&lt;Item&gt; getItems()
{
    System.out.println("Requested!");
    return itemRepository.findAll();
}
</code></pre>

<p>I am trying to retreive the items in my Angular frontend but get the following error:</p>

<pre><code>Access to XMLHttpRequest at 'http://localhost:8080/api/getItems' from origin 
'http://localhost:4200' has been blocked by CORS policy: Response to 
preflight request doesn't pass access control check: No 'Access-Control- 
Allow-Origin' header is present on the requested resource.
</code></pre>

<p>But I am not sure why, because I am adding the correct header in Angular:</p>

<pre><code>getItems() {
this.http.get('http://localhost:8080/api/getItems',
  {headers: new HttpHeaders({
      'Access-Control-Allow-Origin': 'http://localhost:4200',
      'Access-Control-Allow-Methods': 'GET, POST, PUT',
      'Access-Control-Allow-Headers': 'Content-Type'
    }
  )})
  .subscribe(
  data =&gt; {console.log(data);
  });
}
</code></pre>

<p>The get request does work in Postman, but I know that the browser is what is causing the problem, and requires that the 'Access-Control-Allow-Origin' header to be present, which I added.
It compiles, but it seems like it's not adding the headers correctly. Does anyone know what's going on here?</p>
