如何在 Angular、spring-boot、maven 项目中配置项目以自动重新加载浏览器

     2023-02-27     248

关键词:

【中文标题】如何在 Angular、spring-boot、maven 项目中配置项目以自动重新加载浏览器【英文标题】:How to configure project to auto reload browser in angular, spring-boot, maven project 【发布时间】:2019-01-15 03:31:33 【问题描述】:

该项目使用 Maven、Spring Boot、Angular、Visual Studio Code 编辑器。

如何配置项目以在 Angular 文件更改时重新加载浏览器?

spring-boot with angular app

通过 pom.xml 中的这种依赖关系,当 java 文件更改时,浏览器会重新加载。

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <scope>runtime</scope>
</dependency>

【问题讨论】:

ng serve --watch 有什么问题? 应用在$ mvn spring-boot:runlocalhost:8080运行 package.json中设置"start": "ng serve --watch"怎么样? 使用live reload怎么样npmjs.com/package/livereload它可以用作chrome插件或代码。 【参考方案1】:

客户端-服务器集成

服务器和客户端项目分别位于端口 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

【讨论】:

将从 spring-boot 检索到的数据转换为 JSON 并在 Angular 前端获取它

】将从spring-boot检索到的数据转换为JSON并在Angular前端获取它【英文标题】:Convertdataretrievedfromspring-boottoJSONandfetchitinangularfront-end【发布时间】:2019-11-1706:14:29【问题描述】:我想从postgresql中的技能实体中检索所有技能,并使用g... 查看详情

angular2 spring-boot项目结构

】angular2spring-boot项目结构【英文标题】:angular2spring-bootprojectstructure【发布时间】:2017-02-1804:22:21【问题描述】:我有一个新的angular2项目,它是使用快速入门中描述的标准文件结构构建的。我正在尝试构建一个API网关并让spring-... 查看详情

在 Spring-Boot 中,我们如何在同一个项目中连接两个数据库(Mysql 数据库和 MongoDB)?

】在Spring-Boot中,我们如何在同一个项目中连接两个数据库(Mysql数据库和MongoDB)?【英文标题】:InSpring-Boot,Howcanweconnecttotwodatabases(MysqldatabaseandMongoDB)inthesameproject?【发布时间】:2015-12-2513:48:09【问题描述】:我正在尝试创建一... 查看详情

使用spring-boot在Jpa查询中出错

】使用spring-boot在Jpa查询中出错【英文标题】:GettingerrorinJpaquerywithspring-boot【发布时间】:2015-07-2700:06:15【问题描述】:从服务器日志我收到以下错误o.s.w.s.m.m.a.HttpEntityMethodProcessor:Written[timestamp=FriMay1501:39:47EDT2015,status=500,error=Int... 查看详情

使用 Angular 7 前端启动 Spring-Boot 应用程序时无法加载资源错误(缺少资源)

】使用Angular7前端启动Spring-Boot应用程序时无法加载资源错误(缺少资源)【英文标题】:FailedtoloadresourceerrorwhenstartingSpring-BootApplicationwithAngular7Frontend(missingresources)【发布时间】:2019-05-1017:27:24【问题描述】:我想用Angular前端构... 查看详情

向服务器发送 POST 请求,服务器的响应为空,Angular - Spring-boot

】向服务器发送POST请求,服务器的响应为空,Angular-Spring-boot【英文标题】:SendPOSTrequesttoserver,Server\'sresponseisnull,Angular-Spring-boot【发布时间】:2019-12-3016:01:17【问题描述】:我想用我的Angular客户端向我的spring-boot服务器发送一个... 查看详情

Spring Boot + Angular 应用程序

...尝试构建一个SpringBoot应用程序,其中Angular将用作前端,Spring-Boot将用作后端。我想让它war可部署。我尝试在网络上搜索许多链接,到目前为止我得到的理解是:Spring-Boot将在8080端口上运行,而Angular将在42 查看详情

如何在spring-boot中禁用静态内容句柄?

】如何在spring-boot中禁用静态内容句柄?【英文标题】:Howtodisablestaticcontenthandleinspring-boot?【发布时间】:2015-02-1406:29:04【问题描述】:我正在使用this链接来配置安全性和spring-boot作为其他的基础。但是spring-boot提供的静态资源... 查看详情

如何在 spring-boot-2 中添加 WebRequestTraceFilter?

】如何在spring-boot-2中添加WebRequestTraceFilter?【英文标题】:HowtoaddWebRequestTraceFilterinspring-boot-2?【发布时间】:2019-01-0204:48:24【问题描述】:我以前有以下配置,但从spring-boot-2.0开始,WebRequestTraceFilter不再可用。@BeanpublicFilterRegist... 查看详情

使用war将spring-boot和angular 7应用程序部署到tomcat 8.5中

】使用war将spring-boot和angular7应用程序部署到tomcat8.5中【英文标题】:Deployspring-bootandangular7applicationusingwarintotomcat8.5【发布时间】:2019-08-1611:47:33【问题描述】:我正在尝试使用war将Angular7+SpringBoot应用程序部署到tomcat中。我已经... 查看详情

在 spring-boot 中如何分离前端和后端机器?

】在spring-boot中如何分离前端和后端机器?【英文标题】:HowseperateFront-End&Back-Endmachineinspring-boot?【发布时间】:2015-10-1017:27:37【问题描述】:我想将后端和前端(HTML页面)机器分开。后端将由Spring-Boot开发。如何将控制器中... 查看详情

如何在 spring-boot 中配置 Jetty(很容易?)

】如何在spring-boot中配置Jetty(很容易?)【英文标题】:HowtoconfigureJettyinspring-boot(easily?)【发布时间】:2013-12-2514:34:17【问题描述】:按照本教程,我可以使用以下依赖项启动运行Jetty的spring-boot。<dependency><groupId>org.spri... 查看详情

如何在 Spring-Boot 2 中禁用安全性? [复制]

】如何在Spring-Boot2中禁用安全性?[复制]【英文标题】:HowtodisablesecurityinSpring-Boot2?[duplicate]【发布时间】:2019-01-0306:44:00【问题描述】:在spring-boot-1.x中,我有以下配置来禁用开发模式下的基本安全性:application.properties:security.b... 查看详情

如何在 gradle 中获取 spring-boot 依赖版本?

】如何在gradle中获取spring-boot依赖版本?【英文标题】:Howtogetspring-bootdependencyversioningradle?【发布时间】:2017-07-0522:16:50【问题描述】:我有一个带有org.springframework.boot:spring-boot-gradle-plugin的标准spring-boot项目。我知道我可以用例... 查看详情

带有spring-boot安全休息api的角度2

】带有spring-boot安全休息api的角度2【英文标题】:angular2withspring-bootsecurityrestapi【发布时间】:2017-08-1916:20:15【问题描述】:我正在开发一个web应用程序,它的前端是用Angular2(typescript)编写的,它是从angularcli和SpringBoot1.5.2RELEASE生... 查看详情

如何在 spring-boot 中替换最新的 Jetty 9?

】如何在spring-boot中替换最新的Jetty9?【英文标题】:HowtoreplacelatestJetty9inspring-boot?【发布时间】:2013-12-2514:54:31【问题描述】:在spring-boot中,当我添加以下依赖时,正在使用Jetty8。<dependency><groupId>org.springframework.boot<... 查看详情

如何在 Spring-boot 上启用 TLS 1.2?

】如何在Spring-boot上启用TLS1.2?【英文标题】:HowdoyouenableTLS1.2onSpring-boot?【发布时间】:2015-03-1508:34:41【问题描述】:我正在尝试在Spring-boot1.2.1上的Tomcat上启用TLS1.2。由于SSL握手失败,Android5.0无法连接到默认SSL设置。Android4.4、... 查看详情

Spring-boot / Http call angular 2的角度没有'Access-Control-Allow-Origin' [重复]

】Spring-boot/Httpcallangular2的角度没有\\\'Access-Control-Allow-Origin\\\'[重复]【英文标题】:No\'Access-Control-Allow-Origin\'inangularwithSpring-boot/Httpcallangular2[duplicate]Spring-boot/Httpcallangular2的角度没有\'Access-Control-Allow 查看详情