Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用SpringBootAPI REST对JS作出反应_Reactjs_Rest_Spring Boot - Fatal编程技术网

Reactjs 使用SpringBootAPI REST对JS作出反应

Reactjs 使用SpringBootAPI REST对JS作出反应,reactjs,rest,spring-boot,Reactjs,Rest,Spring Boot,我有一个用React JS开发的前端webapp,还有一个用Spring boot构建的rest API。当我尝试从我的react应用程序访问API时,我得到一个403错误。我的API Rest部署在tomcat服务器中 POST http://localhost:8080/fantasy/api/auth/signin 403 PostData.js:3 Uncaught (in promise) SyntaxError: Unexpected end of JSON input 很可能您的

我有一个用React JS开发的前端webapp,还有一个用Spring boot构建的rest API。当我尝试从我的react应用程序访问API时,我得到一个403错误。我的API Rest部署在tomcat服务器中

POST http://localhost:8080/fantasy/api/auth/signin 403
PostData.js:3 Uncaught (in promise) SyntaxError: Unexpected end of JSON input

很可能您的ReactJs应用程序和Spring Boot应用程序在不同的端口下运行,您没有在Spring Rest映射方法中配置CORS,以便启用来自运行ReactJs的主机:端口的传入请求:

@CrossOrigin(origins = "http://localhost:4200")
@GetMapping("/user")
public Greeting getUser(){}
您还可以在控制器本身上定义它:

@CrossOrigin(origins = "http://localhost:4200")
@RestController

您还可以为整个应用程序注册一个单独的CORS筛选器:

信息不足我们需要更多信息来告诉您一些事情。首先,您可以从前端应用程序向我们提供一些日志。然后,给我们您试图到达的其他端点。另外,告诉我们您的rest api的配置。在开发中是一个好主意,但是如果在生产中我的应用程序更改了端口号,那么您可以使用CORS过滤策略。在过滤器中,您从属性文件中注入了一个端口号,这对于开发人员和产品来说当然是不同的。我如何做到这一点呢?我在答案中放置了一个引用。我的spring boot中的upCORS过滤策略可能与Tomcat CORS配置冲突吗?