I am developing a Spring boot application with a Rest interface and popping darts.
XMLHttpRequest executes an OPTIONS request, which is processed completely correctly. After that, the final GET request is issued ("/ products") and does not execute:
No header "Access-Control-Allow-Origin" is present on the requested resource. The origin of http: // localhost: 63343 'is therefore not allowed.
After some debugging, I found the following: The AbstractHandlerMapping.corsConfiguration function is populated for all subclasses except the RestHandlerMapping repository. In RepositoryRestHandlerMapping no corsConfiguration is present / set at creation time and therefore will not be recognized as a cors path / resource.
=> No CORS headers
Could this be a problem? How can i install it?
Configuration classes:
@Configuration public class RestConfiguration extends RepositoryRestMvcConfiguration { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowCredentials(false).allowedOrigins("*").allowedMethods("PUT", "POST", "GET", "OPTIONS", "DELETE").exposedHeaders("Authorization", "Content-Type"); } ... }
I even tried installing Cors for annotation:
@CrossOrigin( methods = RequestMethod.GET, allowCredentials = "false") public interface ProductRepository extends CrudRepository<Product, String> { }
Raw Request Headers:
GET /products HTTP/1.1 Host: localhost:8080 Connection: keep-alive Cache-Control: max-age=0 authorization: Basic dXNlcjpwYXNzd29yZA== User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36 Content-Type: application/json Accept: */* Referer: http://localhost:63343/inventory-web/web/index.html Accept-Encoding: gzip, deflate, sdch Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Headers of the original answer:
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/hal+json;charset=UTF-8 Transfer-Encoding: chunked Date: Thu, 30 Jul 2015 15:58:03 GMT
Used Versions: Spring Download 1.3.0.M2 Spring 4.2.0.RC2
What am I missing?
java spring spring-data-rest spring-mvc cors
Thomas Letsch Jul 30 '15 at 13:20 2015-07-30 13:20
source share