I've a SpringBoot Controller as follows
@CrossOrigin(origins="*")
public class FormController {
@PostMapping(path="/basicForm")
public String postResponseController(
@RequestBody FormDomain loginForm) {
System.err.println("basic form method called");
return "file transfer completed successfully";
}
}
I've annotated the controller with @CrossOrigin(origins="*")
to enable CORS.
Here is my FormDomain Class
public class FormDomain {
private MultipartFile fileInput;
public MultipartFile getFileInput() {
return fileInput;
}
public void setFileInput(MultipartFile fileInput) {
this.fileInput = fileInput;
}
}
And the angular script calling the controller method
onClickSubmit(data) {
this.http.post("http://localhost:8080/basicForm", data).subscribe( (ob)=>(console.log(ob)));
}
Eventhough I've annotated the controller to enable CORS I get following error in browser console
Access to XMLHttpRequest at 'http://localhost:8080/basicForm' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
How to solve this issue?