繁体   English   中英

如何将带有angular 2前端(angular-cli构建)的spring-boot webapp部署到Tomcat?

[英]How can I deploy a spring-boot webapp with angular 2 frontend (angular-cli build) to Tomcat?

我有一个spring-boot Web应用程序,并使用angular-cli构建了前端。 我已在angular-cli.json我的角度构建的输出目录设置为resources / static,并在package.json配置了构建脚本,如下所示:

"scripts" : {"build": "ng build --base-href /mywebapp", ...}

在spring-boot配置的application.properties中,我已将server.contextPath设置为“ mywebapp”。

但是,如果我构建角度应用程序,则在resources / static中创建的index.html包含的js文件不包含服务器上下文路径“ mywebapp”:

<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>

但我应该看起来像这样:

<script type="text/javascript" src="/mywebapp/inline.bundle.js"></script>
<script type="text/javascript" src="/mywebapp/polyfills.bundle.js"></script>

因此,如果我将spring-boot应用程序部署到tomcat,则已加载已构建的index.html,但找不到导入的js文件,并尝试将其加载到http:// localhost:8080 /而不是http:// localhost:8080下/ mywebapp /

如果我不想将它与角度前端的spring-boot应用程序部署到tomcat服务器,该如何将其部署在根目录下?

请查看我使用'--deploy-url'参数的答案。 https://stackoverflow.com/a/43741602/5633515

就您而言,请使用--deploy-url="/mywebapp/"

我有同样的问题,首先我创建了一个pom.xml文件,然后在这里我使用了插件将我的包转换为war文件。

<plugins>

  <!-- ############################## -->
  <!-- npm scripts                    -->
  <!-- ############################## -->

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>exec-project-dependencies-install</id>
        <phase>generate-sources</phase>
        <configuration>
          <executable>npm</executable>
          <arguments>
            <argument>install</argument>
          </arguments>
        </configuration>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>

      <!-- run `ng build -prod -aot` -->
      <!-- * clean dist/ before generating distribution files -->
      <execution>
        <id>exec-compile</id>
        <phase>generate-sources</phase>
        <configuration>
          <executable>npm</executable>
          <arguments>
            <argument>run</argument>
            <argument>ci</argument>
          </arguments>
        </configuration>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <!-- generate zip -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <descriptors>
        <descriptor>src/assembly/static.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
   <!--generate zip -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <descriptors>
        <descriptor>src/assembly/static.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

部署时,我发现了一些问题和不错的讲座。

理论-https: //kosbr.github.io/2016/10/09/angular-build.html

问题-https: //github.com/angular/angular-cli/issues/4517-https : //github.com/angular/angular-cli/pull/4090

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM