I get following error when I am try to access my springboot restservice:
"Failed to load http://localhost:8080/Lerneinheit: 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:8081' is therefore not allowed access. The response had HTTP status code 403."
I googled a lot and added this to my RestController class: "@CrossOrigin(origins = "http://localhost:8081")"
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/Lerneinheit")
public class LerneinheitController {
    @Autowired
    LerneinheitRepository lerneinheitRepository;
    @RequestMapping(method=RequestMethod.GET)
    public List<Lerneinheit> getAllLerneinheiten(){
        List<Lerneinheit> lerneinheiten = new ArrayList<Lerneinheit>();
        for(Lerneinheit l : lerneinheitRepository.findAll())
            lerneinheiten.add(l);
        return lerneinheiten;
    }
and this is my jQuery code to access the data:
var data = {}
    data["query"] = $("#query").val();
    $.ajax({
        type : "POST",
        contentType : "application/json",
        url : "http://localhost:8080/Lerneinheit",
        data : JSON.stringify(data),
        dataType : 'json',
        timeout : 100000,
        success : function(data) {
            console.log("SUCCESS: ", data);
        },
        error : function(e) {
            console.log("ERROR: ", e);
        },
        done : function(e) {
            console.log("DONE");
        }
    });
The server is running on port 8080 and my client page is running with "gulp-live-server": "0.0.31" on port 8081.
I tried a lot and it would be really cool if somebody could help me.
cheers, JohnRamb0r
 
    