[英]How can I deploy a spring-boot webapp with angular 2 frontend (angular-cli build) to Tomcat?
I have a spring-boot web application and I build my frontend with angular-cli. 我有一个spring-boot Web应用程序,并使用angular-cli构建了前端。 I have set the output directory of my angular build in
angular-cli.json
to resources/static and I have configured the build script in package.json
like this: 我已在
angular-cli.json
我的角度构建的输出目录设置为resources / static,并在package.json
配置了构建脚本,如下所示:
"scripts" : {"build": "ng build --base-href /mywebapp", ...}
In the application.properties of the spring-boot configuration I have set the server.contextPath
to 'mywebapp'. 在spring-boot配置的application.properties中,我已将
server.contextPath
设置为“ mywebapp”。
But if I build the angular application the included js files of the created index.html in resources/static does not contain the server context path '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>
but I should look like this: 但我应该看起来像这样:
<script type="text/javascript" src="/mywebapp/inline.bundle.js"></script>
<script type="text/javascript" src="/mywebapp/polyfills.bundle.js"></script>
So if I deploy my spring-boot app to tomcat the built index.html is load but it cannot find the imported js files and tries to load the files under http://localhost:8080/ instead of http://localhost:8080/mywebapp/ . 因此,如果我将spring-boot应用程序部署到tomcat,则已加载已构建的index.html,但找不到导入的js文件,并尝试将其加载到http:// localhost:8080 /而不是http:// localhost:8080下/ mywebapp / 。
How can I deploy a spring-boot application with an angular-frontend to a tomcat server if I don't want to deploy it under the root directory? 如果我不想将它与角度前端的spring-boot应用程序部署到tomcat服务器,该如何将其部署在根目录下?
Please take a look at my answer for using '--deploy-url' parameter. 请查看我使用'--deploy-url'参数的答案。 https://stackoverflow.com/a/43741602/5633515
https://stackoverflow.com/a/43741602/5633515
In your case, use --deploy-url="/mywebapp/"
就您而言,请使用
--deploy-url="/mywebapp/"
I've had the same question, first I've created a pom.xml file and there I've used plugins to convert my package to a war file . 我有同样的问题,首先我创建了一个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>
when deploying I've found some issues and good lectures. 部署时,我发现了一些问题和不错的讲座。
Theory - https://kosbr.github.io/2016/10/09/angular-build.html 理论-https: //kosbr.github.io/2016/10/09/angular-build.html
Issues - https://github.com/angular/angular-cli/issues/4517 - https://github.com/angular/angular-cli/pull/4090 问题-https: //github.com/angular/angular-cli/issues/4517-https : //github.com/angular/angular-cli/pull/4090
hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.