我有一个spring-boot网络应用程序,我用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服务器?
2 回答
请查看我使用'--deploy-url'参数的答案 . https://stackoverflow.com/a/43741602/5633515
在您的情况下,使用
--deploy-url="/mywebapp/"
我有同样的问题,首先我创建了一个pom.xml文件,然后我使用插件将我的包转换为war文件 .
在部署时我发现了一些问题和好的讲座 .
理论 - 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
希望能帮助到你 .