I am new to full-stack application .I had used angular11 in Front-End and Spring-boot Gradle project with JPA rest-service in Back-End.
My Angular Method
addTodos(todo:Todos)
{
return this.http.put('http://localhost:8082/addTodo',JSON.stringify(todo))
}
My Rest Service
@PutMapping(path="/addTodo" ,consumes=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Todo> addTodo(@RequestBody Todo todo) {
todoservice.addTodos(todo);
return new ResponseEntity<Todo>(todo,HttpStatus.OK);
}
My Error in browser is:Access to XMLHttpRequest at 'http://localhost:8082/addTodo' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
How to solve it?. Any help will be appreciable,thanks in advance.