title: SOLVED - Write to Angular 9 Socket from Java Spring - Blocked by CORS Policy
body: <p>I am running into an issue attempting to open a SockJS socket in an Angular 9 application and write to this socket from a Spring backend using the SimpMessageTemplate. The main goal of this task is to receive and display incoming data in realtime with out polling.</p>
  
  <p>I based my original implementation off of an existing <a href="https://github.com/mouadelfakir/websocket-angular-spring-boot-example" rel="nofollow noreferrer">repository</a> done by <a href="https://github.com/mouadelfakir" rel="nofollow noreferrer">mouadelfakir</a> but the implementation used older versions of the software (Angular ~1 and Spring Boot ~1.5). When updating to newer versions, the Angular 9 update provided no change in how the application worked but upgrading to Spring Boot 2.2.6 breaks the implementation. </p>
  
  <p>Upon the Angular application trying to connect to the back end Spring application, the console outputs the following two errors:</p>
  
  <pre><code>- Access to XMLHttpRequest at 'http://localhost:8080/websocket-backend/socket/info?t=1589733936852' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  - GET http://localhost:8080/websocket-backend/socket/info?t=1589733936852 net::ERR_FAILED
  </code></pre>
  
  <p>At the time of writing this post, I have tried a lot of the other remedies that I have seen recommended online, such as creating a proxy that the Angular application run ons or implementing a filter to add the Cross-Origin-Request-Policy in Spring but nothing has worked. A majority of these posts were older and I feel that they may no longer be valid due to the updated software. </p>
  
  <p>Here is my <a href="https://github.com/jakeocinco/websocket-angular-spring-boot-example" rel="nofollow noreferrer">current fork</a> of the example repository that I used which features the software upgrades that I am trying to use.</p>
  
  <p>Edit: Thanks for the feedback on this I was able to resolve the issue. It was caused by the upgrade to the newer version of Spring but was actually due to the deprecation of a key the original develop used in application.properties that kept slipping by me. Updated code exists on my <a href="https://github.com/jakeocinco/websocket-angular-spring-boot-example" rel="nofollow noreferrer">current fork</a> should anyone need it. </p>