簡體   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