该项目使用 Maven、Spring Boot、Angular、Visual Studio Code 编辑器。
如何配置项目以在 Angular 文件更改时重新加载浏览器?
通过 pom.xml 中的此依赖项,浏览器会在 java 文件更改时重新加载。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
最佳答案
客户端-服务器集成
服务器和客户端项目分别位于端口 8080 和 4200 上。
客户端项目的服务器将是“前端”(localhost:4200),所有请求都将由该服务器提供服务,但带有“/”模式的 URL 除外。
4200 处的客户端服务器会将任何“/”请求代理到“后端”服务器(本地主机:8080)。
要配置此设置,请创建一个包含以下内容的文件“proxy.conf.json”。
{
"/" :{
"target" : "http://localhost:8080",
"secure" : false
}
}
修改package.json中的“start”脚本:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
启动“前端”
npm start
启动“后端”
mvn spring-boot:run
关于java - 如何在 Angular、Spring-Boot、Maven 项目中配置项目自动重新加载浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736997/