代码之家  ›  专栏  ›  技术社区  ›  rahul shalgar

角5与弹簧MVC的集成

  •  1
  • rahul shalgar  · 技术社区  · 6 年前

    我正在尝试使用SpringMVC(第五版)和Angular5制作一个基于Web的应用程序…我的想法是,SpringMVC将提供RESTful Web服务,Angular5将在客户端调用这些Web服务和管理用户界面。

    我的问题是,是否需要在服务器上运行两个单独的Web应用程序(一个用于UI,一个用于Web服务)?如果是-什么是Angular5应用程序的Web服务器?如果没有-我们如何将角5与弹簧MVC整合?…有人能给我提供一个工作示例吗?如何实现角为5的弹簧MVC?在单个Web服务器上同时运行这两个应用程序是一个好的实践吗?你有什么建议?

    任何帮助都将非常感谢…提前多谢……

    2 回复  |  直到 6 年前
        1
  •  2
  •   bhavin jalodara    6 年前

    1)您必须在服务器上运行2个Web应用程序。

    2)您可以构建角度项目,然后从中复制所有文件 dist 角度项目目录 WebContent Spring项目目录。

    3)

    按照以下步骤在单个服务器上运行带有Angular5的SpringMVC。

    1.Create normal Dynamic web project.
    2.Add all dependancy required for spring or user maven pom.xml
    3.Open CMD, navigate to angular2 application. Hit command
    
    'npm install'
    
    and then
    
    'ng build'
    
    or use 'ng build --prod' for production build.
    this command will create a “dist” folder, copy all files including all folders.
    
    4. Paste those files and folders into 'WebContent' directory.
    5. Last thing, you need to change basehref=”./” in index.html.
    

    现在您已经准备好运行服务器了,或者您可以部署war文件并将其与Tomcat或其他服务器一起使用。

    我发现Git repo包含了带角2的弹簧MVC的完整工作示例: https://github.com/rakshitshah94/Angular2-SpringBoot-Example

    4)不,在SpringMVC项目中包含角度构建文件并不是一个好的实践。因为每次对angular进行更改时,都必须重新构建SpringWar文件,并再次将其部署到Web服务器。

        2
  •  0
  •   abdul subaan    6 年前

    在单个服务器上集成Spring4mvc和Angular2。请参考这个 link . 它的角度也可以是5