如何在同一个域/服务器上部署应用程序AngularJS和Spring宁静的API服务? [英] How to deploy AngularJS app and Spring Restful API service on the same domain/server?

查看:571
本文介绍了如何在同一个域/服务器上部署应用程序AngularJS和Spring宁静的API服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来春AngularJS。我跟着步骤这里 http://spring.io/guides/gs/rest-service/ 建设后端宁静的API,并且将其发送的Json时请求。因此,根据指导,当我运行MVN春天启动:运行Tomcat服务器开始于本地主机:8080

然后我用约曼角度发生器来建立我的角度应用程序。而当我运行咕噜服务我的角内部应用程序,前端应用程序在本地主机上运行:9000

我应该怎么做,使我的角度应用程序可以一起跟我Springboot Tomcat服务器上同一个域提供,也就是说,本地主机:8080

有没有办法,我可以按照示例项目?我发现了以下项目,但仍然不能使,因为我没有在Tomcat上很多背景做它的工作。


  1. https://github.com/robharrop/spring-angularjs

  2. github.com/GermanoGiudici/angularjs-maven-tomcat-seed

  3. github.com/xvit$c$cr/spring-mvc-angularjs


解决方案

您需要采取之一:


  • 内建文件(咕噜构建那么基本上都在dist /目录)

  • 的原始文件(您的index.html和所有的JS原样)

和它们复制到(我建议/公/)以下文件夹之一:<一个href=\"http://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot\">http://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot


  

春季开机就会自动加上位于任何以下目录的静态Web资源:


  
  

/ META-INF /资源/


  
  

/资源/


  
  

/静态/


  
  

/公/


  
  

这意味着,不仅春天启动提供了一个简单的方法来构建Java或Groovy的应用程序,你也可以用它来轻松地部署客户端JavaScript code和一个真正的web服务器环境中测试一下吧!


这将是发展的疼痛然而,由于你将不得不以使每次的前端发生变化时重新复制文件。对于生产你的目标应该是与你的春季部署的应用程序内置文件的版本副本。

有关发展,你可能要考虑让咕噜服务内容角度和运行Tomcat和你的咕噜服务器(它是节点?),使您的前端和后端之间的交叉起源的请求。或者你可以全角度目录只是复制到上面的目录中,但是这是一个短期的做法。

I'm new to Spring and AngularJS. I followed the steps here http://spring.io/guides/gs/rest-service/ to build the back end restful API, and it sends Json upon requests. So, according to the guide, When I run "mvn spring-boot:run" the tomcat server starts at localhost:8080.

Then I used Yeoman angular generator to build my angular app. And when I run "grunt serve" inside my angular app, the front end app runs at localhost:9000.

What should I do so that my angular app can be served together with my Springboot tomcat server on the same domain, say, localhost:8080 ?

Is there a sample project that I can follow? I found the following projects, but still cannot make it work as I don't have much background on tomcat.

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

解决方案

You need to take either:

  • the built files (grunt build then basically everything in the dist/ directory)
  • the raw files (your index.html and all JS as-is)

and copy them into one of the following folders (I recommend /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!

This is going to be a pain for development however since you will have to re-copy the files every time you make a change for the front end. For production your goal should be to deploy a versioned copy of the built files with your spring app.

For development you might want to consider letting grunt serve the Angular content and running both Tomcat and your grunt server (is it node?) and enabling cross origin requests between your front end and back end. OR you could just copy the whole angular directory into one of the above directories but that is a short term approach.

这篇关于如何在同一个域/服务器上部署应用程序AngularJS和Spring宁静的API服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆