這是我第一次使用 Java 后端和 Angular 前端。我正在嘗試構建并運行此專案,但出現此錯誤:“[HPM] 嘗試將請求 /api/v1/mega/building 從 localhost:4200 代理到 http://localhost:8080 時發生錯誤(拒絕)”
我運行 .\gradlew.bat build 來構建 Java 應用程式,并在 angular 和 node js 代碼上運行 npm install 和 npm run start ..
構建專案后是否必須以某種方式啟動 Java 服務器?
這是我的代碼:
主程式
import com.nortal.mega.persistence.BuildingRepository;
import com.nortal.mega.persistence.entity.BuildingDbo;
import lombok.AllArgsConstructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import java.util.Arrays;
@AllArgsConstructor
@SpringBootApplication
public class Main {
private final BuildingRepository buildingRepository;
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
proxy.conf.json 我嘗試將目標更改為 127.0.0.1,[::] 都無濟于事
"/api/*": {
"target": "http://localhost:8080",
"secure": false,
"loglevel": "debug"
}
}
uj5u.com熱心網友回復:
聽起來您的后端沒有運行。要啟動 Spring Boot 應用程式:
./gradlew bootRun
從 Java 應用程式的根目錄
編輯:看起來你在 Windows 上,所以它會像
.\gradlew.bat bootRun
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/395002.html
