如何部署使用Angular和Java Spring-boot创建的Webapp?

时间:2018-08-18 23:42:01

标签: spring angular web

我想将Web应用程序部署到网站上并公开共享。

我已遵循本指南:https://developer.okta.com/blog/2017/12/04/basic-crud-angular-and-spring-boot

我能够将其部署到localhost上,但是如何将该应用程序部署到实时网页上?

1 个答案:

答案 0 :(得分:0)

您可以使用maven构建您的angular应用并将其放入资源包中。这样,使用webServer(例如码头)启动spring时,您将在webServer端口(例如8080)上访问angular应用。

这里是pom.xml的示例。

<plugin>
     <configuration>
         <nodeVersion>${node.version}</nodeVersion>
         <npmVersion>${npm.version}</npmVersion>

     <workingDirectory>${project.basedir}/src/main/frontend/</workingDirectory>
         <outputdir>${project.basedir}/src/main/resources/public/</outputdir>
                    </configuration>
                    <executions>
                        <execution>
                            <id>install node and npm</id>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                        </execution>
                        <execution>
                            <id>npm install</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>npm version</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>-v</arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>run build</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

也在您的angular.json中:

"projects": {
    "[APP_NAME]": {
      "architect": {
        "build": {
          "options": {
            "outputPath": "../resources/public/",
          }
        }
      }
    }
}