简体   繁体   English

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

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

Ive been trying to learn to integrate a reactJS frontend with a springboot backend.我一直在尝试学习将 reactJS 前端与 springboot 后端集成。 Ive build a demo CRUD app with a reactJS frontend, and spring boot java backend, following a tutorial.我已经按照教程构建了一个带有 reactJS 前端和 spring 启动 java 后端的演示 CRUD 应用程序。 Im very new to react and javascript in general, having more experience with the java side of things, and im having a lot of trouble integrating the two halves together.总的来说,我对 React 和 javascript 很陌生,对 java 方面的事情有更多的经验,而且我在将这两部分整合在一起时遇到了很多麻烦。 The react app is inside the file structure of the springboot app. React 应用程序位于 springboot 应用程序的文件结构中。 I have my springboot project running on port 8080 and the react app on 8081. I have both sides 'working', but when i try to start the servlet, and then start the react app, both start working but i get no communication between the two when i try to open the page on localhost:8081 and manipulate the UI.我的 springboot 项目在端口 8080 上运行,react 应用程序在 8081 上运行。我的双方都在“工作”,但是当我尝试启动 servlet,然后启动 react 应用程序时,两者都开始工作,但我之间没有任何通信两个当我尝试在 localhost:8081 上打开页面并操作 UI 时。 Please help a lowly js n00b figure this out, ive been working on it for about a week getting nothing new accomplished.请帮助一个低级的 js n00b 解决这个问题,我已经为此工作了大约一个星期,但没有取得任何新成就。 When i start localhost:8081 i see my front page, but if i click anything, it doesnt work, and i see in console an error like this.当我启动 localhost:8081 时,我看到了我的首页,但是如果我点击任何东西,它就不起作用,我在控制台中看到这样的错误。

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

with an axios error that looks like出现 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

this is the tutorial i followed if its helpful.如果有帮助,这是我遵循的教程。

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

this is the github repo where i have all the code.. https://github.com/SeanRogan/CrudAppDemo/这是我拥有所有代码的 github 存储库.. https://github.com/SeanRogan/CrudAppDemo/

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

backend source code: https://github.com/SeanRogan/CrudAppDemo/tree/master/src/main/java/com/seanrogandev/crudapp/demo后端源码: 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 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 application.properties: https://github.com/SeanRogan/CrudAppDemo/blob/master/src/main/resources/application.properties

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

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

if theres any other relevant info i left out please let me know.如果我遗漏了任何其他相关信息,请告诉我。 thanks in advance.提前致谢。

You are using HTTP on the backend side but react app tries to access with HTTPS. Check the http-common.js file.您在后端使用 HTTP,但 React 应用程序尝试使用 HTTPS 进行访问。检查http-common.js文件。

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

Changing to HTTP should work.更改为 HTTP 应该可以。

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

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