Deploying Spring Boot Applications on Koyeb

Introduction
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.
1. Prerequisites
Before we dive into the deployment process, ensure you have the following:
-
A basic Spring Boot application. If you don't have one, you can quickly generate a project using Spring Initializr with these dependencies:
- Spring Web
- Spring Data JPA
- PostgreSQL Driver
- A GitHub (or GitLab/Bitbucket) repository, where your Spring Boot project is hosted.
- A Neon account. Sign up at Neon
- A Koyeb account. Sign up at Koyeb's website if you don’t have one.
- Maven or Gradle installed, depending on how your Spring Boot project is configured.
2. Setup database
- On Koyeb, instantiate a FREE PostgreSQL database, which will provide a database URL but is limited to 50 hours per month.
-On Neon, instantiate a FREE PostgreSQL database, which will also provide a database URL.
3. Connect database with Spring boot
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
Explanation
- server.port - This is the port where your application will run. We set an environment variable PORT with a fallback of 8080 in case PORT is null.
- spring.datasource.url - This is an environment variable coming from the Neon or Koyeb dashboard.
- spring.datasource.username - This is an environment variable coming from the Neon or Koyeb dashboard.
- spring.datasource.password - This is an environment variable coming from the Neon or Koyeb dashboard.
- spring.config.import - This imports the file where you store your sensitive data.
4. Create a system.properties file
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
5. Create a controller
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";
}
}
6. Push the code to Github
Create a public repository on Github and push your code. Grab the URL of this repository.
7. Deploy on Koyeb
- Enter your koyeb account.
- Go to Services > Web Services > Create web services with Github.
- Connect to Github or paste the public repository URL.
- Wait for the project to build.
- If successful, a public URL will be generated, and everyone can access your Spring Boot application.
Conclusion
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 !
? Reference
- Koyeb - Spring Boot deploy
- Koyeb - Java Reference
? Talk to me
- Github
- Portfolio
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!
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1377
52
How does Java's classloading mechanism work, including different classloaders and their delegation models?
Mar 17, 2025 pm 05:35 PM
Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa
How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?
Mar 17, 2025 pm 05:44 PM
The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra
How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?
Mar 17, 2025 pm 05:43 PM
The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?
Mar 17, 2025 pm 05:46 PM
The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.
How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?
Mar 17, 2025 pm 05:45 PM
The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.


