You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
4 Hrs
7 Min
57 Seg
Curso de Java Spring

Curso de Java Spring

Alejandro Ramírez

Alejandro Ramírez

Desplegar nuestra API con Heroku

34/35
Resources

How to deploy an application on Heroku using JDK 11?

The process of deploying applications on Heroku may seem complicated, but when you follow a step-by-step guide, it becomes a simple and straightforward task. Here, we will explain how to deploy an application on Heroku, using a specific version of the JDK, with precise examples to facilitate the process.

How to prepare the Heroku environment?

  1. Check JDK versions:
    • Heroku uses Java JDK version 8 by default, while our API is built with version 11. To tell Heroku to use this version, we need to create a file called system.properties in the root of the project.
java.runtime.version=11
  1. Configure database:
    • Make sure your PostgreSQL database is correctly configured in Heroku, with initial tables and data.

How to adapt Spring Boot configuration?

  • Change the active development profile to a production one, by modifying the configuration file. However, do not modify application.properties directly. Define a Procfile file in the root of the project:
web: java -jar -Dspring.profiles.active=production build/libs/your-application.jar.

Here, your-application.jar is the name of the generated jar file.

How to perform automatic deployment with Git?

  1. Push the changes:
    • Use the terminal or your development environment to push the system.properties and Procfile files to the master branch of your repository on GitHub or another Git repository connected to Heroku.
git add .git commit -m "Add Heroku deployment configuration"git push
  1. Deploy to Heroku:
    • Run the git push heroku master command to start the deployment. Heroku will automatically grab the project from the master branch, compile it, generate the corresponding jar and deploy the application.

How to verify deployment and authentication?

Once deployed, you can check if your app responds correctly.

  • URL and context path:

    • Initial access to the root URL may return a 404 error, as there is no content in that location by default.
    • Navigate to your application's defined path to see the API in action.
  • Test with Postman:

    • To test the functionality of your API, use Postman to send requests and verify that the data is fetched correctly from the Heroku database. Make sure the authentication settings are set up correctly.

This approach will allow you to control every step towards the successful deployment of a Java application on Heroku, ensuring that everything is configured to work according to your specific needs. Remember that Heroku simplifies the deployment process, allowing you to focus on the development and functionality of your application. Go ahead and keep learning!

Contributions 30

Questions 14

Sort by:

Want to see more contributions, questions and answers from the community?

Tambien se puede sincronizar github con heroku para que al momento de hacer push se suban los cambios automaticamente a heroku

Desplegue mi app en https://railway.app// 😃 Excelente curso!!

Tengo un error con heroku

error: src refspec master does not match any.

Se solventa con :

git push heroku HEAD:master

Por si les sale un error de cors cuando esten consumiendo su api deben agregar la anotacion @CrossOrigin en cada controlador arriba de donde inicia la clase… y tambien se puedne agregar de forma global.
.
https://spring.io/guides/gs/rest-service-cors/

Tengo una consulta en Heroku podemos tener mas de una aplicacion publicada en una licencia gratis o solo deja tener una nada mas, ya que estaba intentando subir una nueva api al servicio.

Heroku ya no es gratis como antes, pero hay muchas más opciones, aquí te dejo una que yo use:

railway

my proyecto

Llegué a tener varios problemas al hacer el despliegue sobre todo en application.properties y con el gradle asi que si tienen problemas con eso, aquí les dejo mi repo y un video que me ayudo I’m video

¡Qué gran tutorial sobre cómo desplegar una aplicación Spring Boot en Heroku! Gracias por compartir tus conocimientos y por ayudarnos a aprender cómo implementar nuestras aplicaciones en un entorno de producción en la nube. Esta es una habilidad valiosa y relevante para cualquier desarrollador de hoy en día, y apreciamos tu experiencia y enseñanza en este tema. ¡Gracias por tu trabajo y por hacer que el aprendizaje sea accesible y emocionante! 👨‍🏫💻🌟

Despliego mi app sin problemas pero cuando trato de consumir cualquier endpoint o swagger me da timeout:

2020-12-14T00:23:33.026436+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-12-14T00:23:33.049360+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-12-14T00:23:33.244126+00:00 heroku[web.1]: Process exited with status 137

En mi caso configure el _Prodfile _ de esta manera:

web: java -jar -Dspring.profiles.active=pdn build/libs/platzi-market-0.0.1-SNAPSHOT.jar

Esta es el API respondiendo desde Heroku

Este es el mio

Muy buen curso! me representó un desafío por la complejidad de algunos temas pero poco a poco se fuero aclarando mis ideas. Mi app: https://market-by-jessytpt.herokuapp.com/app/

Estuvo duro el curso, pero lo logré!

Deploy con heroku

Desplegado con heroku exitosamente

Me encantó el curso, tenía mucho miedo de Spring, pero enseñó bastante bien, increíble el contenido ✨

Muchas gracias!

es procfile no proDfile jeje

Un detalle a tener en cuenta es que .gitignore no añade la carpeta de .gradle, y allí es donde se encontran los archivos de Swagger, si no eliminan o comentan esta linea, no les aparecerá la documentación en heroku

Error: Unable to access jarfile build/libs/fernando-market-1.0.jar

A mi tambien medio este problema alguien mas ? O si me pudieran decir como resolverlo, este error lo obtengo al usar heroku logs --tail

En mi caso configure el _Procfile _ de esta manera:

web: java -jar -Dspring.profiles.active=pdn build/libs/platzi-market-0.0.1-SNAPSHOT.jar

Profesor buenas noches me sale el Sgte. error en consola al ejecutar <git push heroku master>

λ git push heroku master
Enumerating objects: 59, done.
Counting objects: 100% (59/59), done.
Delta compression using up to 4 threads
Compressing objects: 100% (52/52), done.
Writing objects: 100% (59/59), 15.95 KiB | 1.99 MiB/s, done.
Total 59 (delta 8), reused 0 (delta 0), pack-reused 0
remote: Compressing source files… done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: d8ad6b6a922df1b73aa460f94ae9c7f314eab4d7
remote: !
remote: ! We have detected that you have triggered a build from source code with version d8ad6b6a922df1b73aa460f94ae9c7f314eab4d7
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy…
remote:
remote: ! Push rejected to platzimarkethyo.
remote:
To https://git.heroku.com/platzimarkethyo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘https://git.heroku.com/platzimarkethyo.git

Si agrego nuevas funciones a mi aplicación, con el simpre hecho de mandar el push a la rama master de heroku bastaría para que lo actualizara. También si hay alguna manera de que al abrir heroku se redireccione a la url /market/api

Me esta dando problemas al momento de hacer

git push heroku master
error: src refspec master does not match any
error: failed to push some refs to 'https://git.heroku.com/platzimarketmc.git'

Pero mediante la vista web del panel de control de Heroku asociado a nuestra cuenta se puede hacer el mismo despligue si tenemos nuestro código en Github, al comenzar el deploy el log de eventos indica lo mismo que por consola.

A mi si me termino funcionando, pero me sale este error

remote:        > Task :compileJava
remote:        /tmp/build_4502969c/src/main/java/com/platzi/platzimarket/persitence/mapper/CategoryMapper.java:19: warning: Unmapped target properties: "idCategoria, descripcion, estado".
remote:            Categoria toCategoria(Category category);
remote:                      ^
remote:        1 warning