title: No 'Access-Control-Allow-Origin' header - Springboot
body: <p>I get following error when I am try to access my springboot restservice:</p>
  
  <p>"Failed to load <a href="http://localhost:8080/Lerneinheit" rel="nofollow noreferrer">http://localhost:8080/Lerneinheit</a>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:8081" rel="nofollow noreferrer">http://localhost:8081</a>' is therefore not allowed access. The response had HTTP status code 403."</p>
  
  <p>I googled a lot and added this to my RestController class: "@CrossOrigin(origins = "<a href="http://localhost:8081" rel="nofollow noreferrer">http://localhost:8081</a>")"</p>
  
  <pre><code>@CrossOrigin(origins = "http://localhost:8081")
  @RestController
  @RequestMapping("/Lerneinheit")
  public class LerneinheitController {
  
      @Autowired
      LerneinheitRepository lerneinheitRepository;
  
  
      @RequestMapping(method=RequestMethod.GET)
      public List&lt;Lerneinheit&gt; getAllLerneinheiten(){
          List&lt;Lerneinheit&gt; lerneinheiten = new ArrayList&lt;Lerneinheit&gt;();
          for(Lerneinheit l : lerneinheitRepository.findAll())
              lerneinheiten.add(l);
  
          return lerneinheiten;
      }
  </code></pre>
  
  <p>and this is my jQuery code to access the data:</p>
  
  <pre><code>var data = {}
      data["query"] = $("#query").val();
  
      $.ajax({
          type : "POST",
          contentType : "application/json",
          url : "http://localhost:8080/Lerneinheit",
          data : JSON.stringify(data),
          dataType : 'json',
          timeout : 100000,
          success : function(data) {
              console.log("SUCCESS: ", data);
  
          },
          error : function(e) {
              console.log("ERROR: ", e);
  
          },
          done : function(e) {
              console.log("DONE");
          }
      });
  </code></pre>
  
  <p>The server is running on port 8080 and my client page is running with "gulp-live-server": "0.0.31" on port 8081.</p>
  
  <p>I tried a lot and it would be really cool if somebody could help me.</p>
  
  <p>cheers,
  JohnRamb0r</p>