localhost:9090でxamppを実行し、ポート80でxamppを実行しています。ポート80からREST-APIへのPUTリクエスト(Spring 4.2私はいくつかのソリューションを見つけたグーグル後SpringとTomcatでCORSを有効にできません
XMLHttpRequest cannot load http://localhost:9090/rest/location/8609d865-d87a-4340-ab87-0e7f90a6fda9 . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost ' is therefore not allowed access. The response had HTTP status code 403.
- それらのどれも働いていない:0.2)
ポート9090上で、私はこのエラーを取得します。私が試した何
:
-Add私の回答に私のコントローラに
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-Add注釈
@CrossOrigin
@RestController
public class LocationController
-Addヘッダをweb.xmlにフィルタ
return ResponseEntity.status(HttpStatus.OK).header("Access-Control-Allow-Origin", "*").build();
-Addは、それらのOPTIONSルート
@RequestMapping(value = "/**", method = RequestMethod.OPTIONS)
@ResponseBody
public ResponseEntity options(@PathVariable String locationID) {
return ResponseEntity.status(HttpStatus.OK).header("Access-Control-Allow-Origin", "*").build();
}
なし私のために働いていない、私はまだ上記のエラーを受信しています。何か案が?