title: Angular2/Spring Boot Allow Cross Origin on PUT
body: <p>I have a little problem on my web application: an angular2 app connected to a spring boot API.</p>
  
  <p>I can't access my request from the angular2 app. I get this error : </p>
  
  <pre><code>Failed to load http://localhost:8080/deliveryMan/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
  </code></pre>
  
  <p>Java code : </p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/deliveryMan")
  @CrossOrigin
  public class DeliveryManController {
  
      @Autowired
      DeliveryManService deliveryManService;
  
      @RequestMapping(value = "/getAllDeliveryMan", method = RequestMethod.GET)
      public Iterable&lt;DeliveryMan&gt; getAllDeliveryMan(){
          return deliveryManService.findAll();
      }
  
      @RequestMapping(method = RequestMethod.PUT, consumes = "application/json")
      public DeliveryMan addDeliveryMan(@RequestBody DeliveryMan deliveryMan) throws InvalidObjectException {
          deliveryManService.save(deliveryMan);
          return deliveryMan;
      }
  
  @SpringBootApplication
  @EnableAutoConfiguration
  @ComponentScan
  public class MyApp{
  
      public static void main(String[] args) {
          SpringApplication.run(MyApp.class, args);
      }
  }
  </code></pre>
  
  <p>The angular2 code : </p>
  
  <pre><code>private apiUrl = 'http://localhost:8080/deliveryMan/';
  
  getAll(): Promise&lt;DeliveryMan[]&gt; {
    const url = this.apiUrl + 'getAllDeliveryMan';
    return this.http.get(url)
      .toPromise()
      .then(response =&gt; response.json().data as DeliveryMan[])
      .catch(this.handleError);
  }
  
  saveDeliveryMan(deliveryMan: DeliveryMan): Promise&lt;DeliveryMan&gt; {
    const url = this.apiUrl;
    return this.http.put(url, JSON.stringify(deliveryMan), this.headers)
      .toPromise()
      .then(() =&gt; deliveryMan)
      .catch(this.handleError);
  }
  </code></pre>
  
  <p>In order to solve the problem, i added @CrossOrigin to my controller class. 
  It resolves the problem for the getAll method but not for the additional one. </p>
  
  <p>How to resolve it so I can use PUT methods without getting this error? </p>