Run Spring4MVC with Angular 2 on a single server

后端 未结 2 1225
慢半拍i
慢半拍i 2020-12-07 22:23

I am new to angular2, I want to know what is the possible file structure for SpringMVC4 with angular 2?

As shown in image, it will work for Angular 1.x but

2条回答
  •  时光说笑
    2020-12-07 22:31

    You can automate your solution - just use frontend-maven-plugin (with which you can install nodejs and build the angular project) and maven-resources-plugin to copy the contents of /angular/dist/ directory into root of .war file (see also this article)

    
          org.apache.maven.plugins
          maven-resources-plugin
          3.0.2
          
            
              default-copy-resources
              process-resources
              
                copy-resources
              
              
                true
                ${project.build.directory}/${project.artifactId}-${project.version}/
                
                  
                    ${project.basedir}/angular/dist
                  
                
              
            
          
    
    

    And then you can use hot reload feature (while developing) on nodejs server, runned by ng serve with Angular CLI tool.

提交回复
热议问题