加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在同一个域/服务器上部署AngularJS应用程序和Spring Restful

发布时间:2020-12-17 08:13:30 所属栏目:安全 来源:网络整理
导读:我是Spring和AngularJS的新手。我按照步骤 here构建后端安静的API,并根据请求发送Json。所以,根据指南,当我运行“mvn spring-boot:run”时,tomcat服务器从localhost:8080启动。 然后我用Yeoman角度发生器来构建我的角度应用程序。当我在我的角度的应用
我是Spring和AngularJS的新手。我按照步骤 here构建后端安静的API,并根据请求发送Json。所以,根据指南,当我运行“mvn spring-boot:run”时,tomcat服务器从localhost:8080启动。

然后我用Yeoman角度发生器来构建我的角度应用程序。当我在我的角度的应用程序中运行“grunt服务”,前端应用程序运行在localhost:9000。

我应该怎么做,所以我的角度的应用程序可以与我的Springboot tomcat服务器一起提供给同一个域,比如说localhost:8080?

有没有可以跟踪的示例项目?我发现以下项目,但仍然无法使其工作,因为我没有太多的tomcat背景。

> https://github.com/robharrop/spring-angularjs
> https://github.com/GermanoGiudici/angularjs-maven-tomcat-seed
> https://github.com/xvitcoder/spring-mvc-angularjs

你需要采取:

>构建的文件(grunt build然后基本上在dist /目录中的所有内容)
>原始文件(您的index.html和所有JS原样)

并将它们复制到以下文件夹之一(我推荐/ public /):http://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

Spring Boot will automatically add static web resources located within any of the following directories:

/META-INF/resources/

/resources/

/static/

/public/

This means that not only does Spring Boot offer a simple approach to building Java or Groovy apps,you can also use it to easily deploy client-side JavaScript code and test it within a real web server environment!

这将是一个痛苦的发展,因为你必须重新复制文件,每次你改变前端。对于生产,您的目标应该是使用弹簧应用程序部署版本的内置文件副本。

对于开发,您可能需要考虑让grunt服务于Angular内容,并运行Tomcat和您的grunt服务器(是节点?),并在前端和后端之间启用跨源请求。或者您可以将整个角度目录复制到上述目录之一,但这是一种短期方法。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读