title: Cors enabled in Spring Boot with Angular, still cors errors
body: <p>I have cors enabled for all origins and headers but I still get an cors error when I call a <code>get</code> method from my angular app to spring boot.</p>
  <p>Cors error from console:</p>
  <pre><code>Access to XMLHttpRequest at 'http://localhost:8080/api/users/test@ronny.nl' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  </code></pre>
  <p>My <code>controller</code> (I call the getbyemail):</p>
  <pre><code>@CrossOrigin(origins = &quot;*&quot;, allowedHeaders = &quot;*&quot;)
  @RestController
  @RequestMapping(value = &quot;/api/users&quot;, produces = MediaType.APPLICATION_JSON_VALUE)
  public class UserController {
  
      private final UserService userService;
  
      @Autowired
      public UserController(final UserService userService) {
          this.userService = userService;
      }
  
      @GetMapping
      public List&lt;UserDTO&gt; getAllUsers() {
          return userService.findAll();
      }
  
      @GetMapping(&quot;/{id}&quot;)
      public UserDTO getUser(@PathVariable final Long id) {
          return userService.get(id);
      }
  
      @CrossOrigin(origins = &quot;*&quot;, allowedHeaders = &quot;*&quot;)
      @GetMapping(&quot;/{email}&quot;)
      public UserDTO getUserByMail(@PathVariable String email) {
          return userService.getByEmail(email);
      }
  
      @PostMapping
      @ResponseStatus(HttpStatus.CREATED)
      public Long createUser(@RequestBody @Valid final UserDTO userDTO) {
          return userService.create(userDTO);
      }
  
      @PutMapping(&quot;/{id}&quot;)
      public void updateUser(@PathVariable final Long id, @RequestBody @Valid final UserDTO userDTO) {
          userService.update(id, userDTO);
      }
  
      @DeleteMapping(&quot;/{id}&quot;)
      @ResponseStatus(HttpStatus.NO_CONTENT)
      public void deleteUser(@PathVariable final Long id) {
          userService.delete(id);
      }
  
  }
  </code></pre>
  <p>Where I call the get from my angular app:</p>
  <pre><code>onSubmit(): void {
      this.submitted = true;
      this.wrongInput = false;
      this.loginService.getLogin&lt;User&gt;(this.loginForm.value.email).subscribe((response) =&gt; {
        this.tempUser = response;
        console.log(this.tempUser);
        if (this.loginForm.value.email === this.tempUser.email &amp;&amp; this.loginForm.value.password === this.tempUser.password) {
          this.localStorageService.save(this.tempUser);
          this.router.navigate(['/home']);
          console.log(true);
        }
        else {
          this.wrongInput = true;
        }
      });
    }
  </code></pre>
  <p>I also tried to add an <code>DevCorsConfiguration</code>:</p>
  <pre><code>package com.team13.triviaquiz.triviaquizserver.config;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Profile;
  import org.springframework.web.servlet.config.annotation.CorsRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  
  @Configuration
  @Profile(&quot;development&quot;)
  public class DevCorsConfiguration implements WebMvcConfigurer {
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping(&quot;/api/**&quot;).allowedMethods(&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;, &quot;PATCH&quot;, &quot;DELETE&quot;, &quot;OPTIONS&quot;);
      }
  }
  </code></pre>
  <p>And added the profile in my <code>application.properties</code>:</p>
  <pre><code>application.properties
  spring.profiles.active=development
  #enabling h2 console
  spring.h2.console.enabled=true
  #fixed URL for H2 (necessary from Spring 2.3.0)
  spring.datasource.url=jdbc:h2:mem:triviaquizserver
  #turn statistics on
  spring.jpa.properties.hibernate.generate_statistics = true
  logging.level.org.hibernate.stat=debug
  #show all queries
  spring.jpa.show-sql=true
  spring.jpa.properties.hibernate.format_sql=true
  logging.level.org.hibernate.type=trace
  </code></pre>
  <p>But still no luck...</p>