Java 问题Cors:否';访问控制允许原点';请求的资源上存在标头
我无法解决这个错误;我补充说 @交叉原点(原点=”http://localhost:4200") 但错误依然存在 RestAPIController.javaJava 问题Cors:否';访问控制允许原点';请求的资源上存在标头,java,spring,cors,same-origin-policy,Java,Spring,Cors,Same Origin Policy,我无法解决这个错误;我补充说 @交叉原点(原点=”http://localhost:4200") 但错误依然存在 RestAPIController.java import org.springframework.beans.factory.annotation.Autowired; 导入org.springframework.http.HttpStatus; 导入org.springframework.http.ResponseEntity; 导入org.springframework.we
import org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.http.HttpStatus;
导入org.springframework.http.ResponseEntity;
导入org.springframework.web.bind.annotation.DeleteMapping;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.PostMapping;
导入org.springframework.web.bind.annotation.PutMapping;
导入org.springframework.web.bind.annotation.RequestBody;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RestController;
(起源=”http://localhost:4200")
@RestController
@请求映射(“/api/customer”)
公共类重启控制器{
@自动连线
客户服务客户服务;
@后映射(“/create”)
公共响应名称addNewCustomer(@RequestBody-Customer){
试一试{
Customer returnedCustomer=customerServices.saveCustomer(客户);
返回新的响应属性(新消息(“上载成功!”),
Arrays.asList(returnedCustomer),“”),HttpStatus.OK);
}捕获(例外e){
返回新的ResponseEntity(新消息(“未能发布新客户!”),
null,例如getMessage()),HttpStatus.INTERNAL\u SERVER\u错误);
}
}
.
.
.
.
}
这是一个老问题
您应该在扩展webmvcconfiguer
registry.addMapping("/**")
.allowCredentials(true)
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("http://localhost:3000")
.maxAge(3600);
}
这回答了你的问题吗?同样的问题已经得到了回答。我已经尝试了所有的方法,我在这里尝试了几个例子,但问题仍然存在。否则我就不会问这个问题了,我已经尝试了各种方法,我在这里尝试了几个例子,但问题仍然存在。否则我就不会问这个问题了,也可以在SecurityConfig中添加http.cors()。如果它仍然不起作用。只需点击这里的源代码链接。也许有人能帮忙。