title: Access to XMLHttpRequest at 'https://...' from origin 'http://...' has been blocked by CORS policy(Spring Boot & Angular 7)
body: <p>I am creating a sample application using Spring Boot and Angular 7. In spring boot I am converting http to https. In angular application the client side post functionality cannot call the server Api post method.</p>
  
  <p>It throws the below error</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at '<a href="https://localhost:8082/Demo/list" rel="nofollow noreferrer">https://localhost:8082/Demo/list</a>' from origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
  </blockquote>
  
  <p><strong>Client Side</strong> Angular 7</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {HttpClient} from '@angular/common/http';
  
  @Injectable({
    providedIn: 'root'
  })
  export class DataService {
  
    constructor(private http: HttpClient) { }
  
    firstClick() {
      return console.log('clicked');
    }
    getList() {
      return this.http.get('https://localhost:8082/Demo/list');
    }
  }
  </code></pre>
  
  <p><strong>Client Side</strong></p>
  
  <pre><code>  constructor(private data: DataService) {}
  
    ngOnInit() {
       this.data.getList().subscribe(data =&gt; {
         this.tempList = data
         console.log(this.tempList);
       });
    }
  </code></pre>
  
  <p><strong>Server</strong></p>
  
  <pre><code>@CrossOrigin(origins = "http://localhost:4200")
  @Controller
  </code></pre>