繁体   English   中英

React 前端未与 spring 引导 REST API 通信。控制台中的 Axios.network 错误

[英]React front end is not communicating with spring boot REST API. Axios network err in console

我一直在尝试学习将 reactJS 前端与 springboot 后端集成。 我已经按照教程构建了一个带有 reactJS 前端和 spring 启动 java 后端的演示 CRUD 应用程序。 总的来说,我对 React 和 javascript 很陌生,对 java 方面的事情有更多的经验,而且我在将这两部分整合在一起时遇到了很多麻烦。 React 应用程序位于 springboot 应用程序的文件结构中。 我的 springboot 项目在端口 8080 上运行,react 应用程序在 8081 上运行。我的双方都在“工作”,但是当我尝试启动 servlet,然后启动 react 应用程序时,两者都开始工作,但我之间没有任何通信两个当我尝试在 localhost:8081 上打开页面并操作 UI 时。 请帮助一个低级的 js n00b 解决这个问题,我已经为此工作了大约一个星期,但没有取得任何新成就。 当我启动 localhost:8081 时,我看到了我的首页,但是如果我点击任何东西,它就不起作用,我在控制台中看到这样的错误。

localhost:8080/api/tutorials:1 加载资源失败:.net::ERR_SSL_PROTOCOL_ERROR

出现 axios 错误,看起来像

AxiosError
code: "ERR_NETWORK"
config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
message: "Network Error"
name: "AxiosError"
request: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …}
response: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …}
[[Prototype]]: Error

如果有帮助,这是我遵循的教程。

https://www.bezkoder.com/react-spring-boot-crud/#Create_038_Setup_Spring_Boot_project

这是我拥有所有代码的 github 存储库.. https://github.com/SeanRogan/CrudAppDemo/

前端源码: https://github.com/SeanRogan/CrudAppDemo/tree/master/frontend/src

后端源码: https://github.com/SeanRogan/CrudAppDemo/tree/master/src/main/java/com/seanrogandev/crudapp/demo

pom.xml: https://github.com/SeanRogan/CrudAppDemo/blob/master/pom.xml

application.properties: https://github.com/SeanRogan/CrudAppDemo/blob/master/src/main/resources/application.properties

清单.json:https://github.com/SeanRogan/CrudAppDemo/blob/master/frontend/public/manifest.json

package.json: https://github.com/SeanRogan/CrudAppDemo/blob/master/frontend/package.json

如果我遗漏了任何其他相关信息,请告诉我。 提前致谢。

您在后端使用 HTTP,但 React 应用程序尝试使用 HTTPS 进行访问。检查http-common.js文件。

baseURL: "https://localhost:8080/api",

更改为 HTTP 应该可以。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM