[Vuejs]-How to allow cors policy on fetch of vue.js to backend?

5👍

Try adding @RequestMapping("/") between @RestController and @CrossOrigin and delete headers = ("Access-Control-Allow-Origin: *"). It is confusing Spring if you don’t add RequestMapping in class level or adding extra headers in method level I believe.

@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequestMapping("/")
@RestController
public class TodoListController {
    @Autowired
    TaskService taskService;

    @GetMapping(value = "/getTasks")
    public List<Task> getTasks() {
        return taskService.getAllTasks();
    }
    ...
}

Leave a comment