When we start building things as developers, one of our key goals is to share what we've created with others. For frontend developers, this is often straightforward, thanks to great hosting services like Vercel and Netlify that support frontend apps seamlessly. However, for backend developers, showcasing our work can be more challenging. We build APIs, work with databases, and while JSON might be powerful, it’s not as visually compelling as an animation built with CSS or Lottie.
That’s why finding an efficient and reliable way to deploy backend applications is crucial. Spring Boot, a popular Java-based framework, simplifies the process of building production-ready applications, but deploying them can still be a challenge. This is where Koyeb comes in. Koyeb offers a powerful and easy-to-use platform that allows developers to deploy their Spring Boot applications quickly with minimal setup. In this guide, we’ll walk you through the entire process of deploying a Spring Boot application with a PostgreSQL database on Koyeb, from start to finish.
Before we dive into the deployment process, ensure you have the following:
-On Neon, instantiate a FREE PostgreSQL database, which will also provide a database URL.
Inside the resources directory you are going to create a file called env.properties, inside of that store all your environment variables, in this case DB_URL, DB_USERNAME and DB_PASSWORD.
NEVER COMMIT this file to the repository of your github.
env.properties file:
DB_USERNAME=<Get this from the Neon or Koyeb dashbord> DB_PASSWORD=<Get this from the Neon or Koyeb dashbord> DB_URL=<Get this from the Neon or Koyeb dashbord>
Your application.properties file:
application.propertiesfile:
server.port=${PORT:8080} spring.datasource.url=${DB_URL} spring.datasource.username=${DB_USERNAME} spring.datasource.password=${DB_PASSWORD} spring.jpa.hibernate.ddl-auto=update spring.config.import=classpath:env.properties
At the root of the project, create a system.properties file.
This file specifies the Java runtime version to use so that the Koyeb Java buildpack executes the project with the correct version.
Remember: Koyeb accepts major version values 1.8, 11, 13, 15, 17, 19, and 20.
If you do not specify a Java version, version 1.8 will be used.
I’m using Java 21. If you are using another version, change it accordingly.
system.properties
java.runtime.version=21
This controller will display the Hello World message at the / route.
package com.example.demo.Modules.User.controller; import org.springframework.web.bind.annotation.RestController; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @RestController public class UserController { @GetMapping("/") public String helloWorld() { return "Hello World"; } }
Create a public repository on Github and push your code. Grab the URL of this repository.
That’s it! You’ve created a Spring Boot application, connected it with a cloud database, and deployed everything on Koyeb. This can be the start of a project you want to showcase in your portfolio, allowing clients to see what you can do.
You can increment this application with a Image Uploader Article.
Thanks for reading !
The above is the detailed content of Deploying Spring Boot Applications on Koyeb. For more information, please follow other related articles on the PHP Chinese website!