title: No 'Access-Control-Allow-Origin' Angular->SpringBoot
body: <p>I'm trying call the Angular2 a one Service the SpringBoot, but When I do call I get this error : </p>
  
  <p><a href="https://i.stack.imgur.com/oMKS6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oMKS6.png" alt="error"></a></p>
  
  <p>In my SpringBoot I have:</p>
  
  <pre><code>package com.service.configure;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.HttpMethod;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.builders.WebSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.config.http.SessionCreationPolicy;
  
  @Configuration
  @EnableWebSecurity
  @ComponentScan(basePackages = "com.service")
  public class ServiciosConfig  extends WebSecurityConfigurerAdapter {
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers(HttpMethod.OPTIONS);
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.csrf().disable();
          http.authorizeRequests().antMatchers("/").permitAll().anyRequest().authenticated().and().httpBasic().and()
                  .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); 
      }
  
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
           auth.inMemoryAuthentication().withUser("admin").password("admin").roles("USER");
  
      } 
  
  }
  </code></pre>
  
  <p>In Angular2:</p>
  
  <pre><code>private fetchData() {
          const url = 'http://localhost:8080/pg/get';
          this.service.fetchData(url).subscribe(
              data =&gt; {
                  console.log('mis datos ', data);
                  this.headers = data[0].headers;
                  this.params = data[1].params;
              });
      }
   public fetchData(url: string): Observable&lt;any&gt; {
      let headers = new Headers();
      headers.append("Authorization", "Basic YWRtaW46YWRtaW4=");
      return this.http.get&lt;Object[]&gt;(url);
    }
  </code></pre>
  
  <p>If I put <a href="http://localhost:8080/pg/get" rel="nofollow noreferrer">http://localhost:8080/pg/get</a> I can get datas =).</p>
  
  <p>But If I try with Angular is impossible...</p>
  
  <p>My friend used "postman" and He recives datas</p>
  
  <p>Code PostMan:</p>
  
  <pre><code>var settings = {
    "async": true,
    "crossDomain": true,
    "url": "http://myIp:8080/pg/get",
    "method": "GET",
    "headers": {
      "Authorization": "Basic YWRtaW46YWRtaW4=",
      "Cache-Control": "no-cache",
      "Postman-Token": "e1225c81-8cb0-4809-9a2a-c82776793906"
    }
  }
  
  $.ajax(settings).done(function (response) {
    console.log(response);
  });​
  </code></pre>
  
  <p>My controller : </p>
  
  <pre><code>@RestController
  @RequestMapping(value={"/pg"})
  @CrossOrigin
  public class PgController {
  
      @Autowired
      PgService pgRepository;
  
      @RequestMapping(method=RequestMethod.GET,value="/", produces = MediaType.APPLICATION_JSON_VALUE)
      String home() {
          return "¡Servicio configuración!";
      }
  
  
      @RequestMapping(method=RequestMethod.GET,value="/get", produces = MediaType.APPLICATION_JSON_VALUE)
      public List&lt;tp_parametros_generales&gt; getAllParameters() {
          List&lt;tp_parametros_generales&gt; tasks = pgRepository.getPg();
          return tasks;
      }
  }
  </code></pre>