[英]Spring boot + angular 2 Heroku deployment
I have a big issue. 我有一个大问题。 I'm trying to deploy Spring Boot + Angular 2 web app on heroku but don't know how to do it. 我正在尝试在heroku上部署Spring Boot + Angular 2 Web应用程序,但不知道该怎么做。 I tried several things including: 我试过几件事,包括:
Making a .war file and deploying it to heroku (source here ) 制作.war文件并将其部署到heroku( 此处为源代码)
Deploying project as standard java application (source here ) 将项目部署为标准Java应用程序( 此处为源代码)
but none of these worked. 但这些都没有奏效。 The first attempt didn't work because I constatly got 404 not found, and the second one didn't work due to, I think, some jar file wasn't found in the location which was described in the Procfile. 第一次尝试不起作用,因为我一直没有找到404,而第二次尝试没有用,因为我认为,在Procfile中描述的位置找不到一些jar文件。 Can anyone give me a link, an example, or write a step by step instruction how to achieve this. 任何人都可以给我一个链接,一个例子,或写一步一步的指令如何实现这一目标。 Thank you. 谢谢。
The most simple way to do it: 最简单的方法:
ng build
in angular 2 project root (if you are using angular-cli) and copy the content of dist folder to src/main/resources/static/. 在角度2项目根目录中运行ng build
(如果使用angular-cli)并将dist文件夹的内容复制到src / main / resources / static /。 create Procfile (for maven): 创建Procfile(对于maven):
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar web:java $ JAVA_OPTS -Dserver.port = $ PORT -jar target / * .jar
commit and push changes. 提交并推送更改。
Also, you need spring-boot-starter-web present in dependencies. 此外,您需要在依赖项中存在spring-boot-starter-web。 Which has embedded tomcat and automatically configured to serve static content from the static folder. 其中嵌入了tomcat并自动配置为从静态文件夹中提供静态内容。
If you deploy your app as a standard Java application, you can combine it with the Node.js buildpack to run ng build
during the Heroku build. 如果将应用程序部署为标准Java应用程序,则可以将其与Node.js buildpack结合使用,以在Heroku构建期间运行ng build
build。
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/java
$ git push heroku master
The Node.js buildpack will detect your package.json
, install Node.js and run npm
. Node.js buildpack将检测你的package.json
,安装Node.js并运行npm
。 Then the Java build can proceed as normal. 然后Java构建可以正常进行。
There is a guide for doing something very similar but with Grunt: Using Grunt with Java and Maven to Automate JavaScript Tasks 有一个与Grunt非常相似的指南: 使用Grunt与Java和Maven自动化JavaScript任务
Use JHipster: https://jhipster.github.io 使用JHipster: https ://jhipster.github.io
Once installed, run: 安装完成后,运行:
$ yo jhipster
Then run 然后跑
$ yo jhipster:heroku
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.