Out Plane LogoOut Plane

Spring Boot

Step-by-step guide to deploy a Spring Boot application on Out Plane

This guide walks you through deploying a Spring Boot application on Out Plane using Git-driven deployment with a Dockerfile.

Prerequisites

  • An Out Plane account
  • A GitHub account
  • Java 17+ (JDK) installed on your machine
  • Git installed on your machine

Create the Spring Boot App

  1. Go to start.spring.io
  2. Configure your project:
    • Project: Maven
    • Language: Java
    • Spring Boot: 3.2.x (latest stable)
    • Group: com.example
    • Artifact: myapp
    • Packaging: Jar
    • Java: 17 or 21
  3. Add dependency: Spring Web
  4. Click Generate to download the ZIP
  5. Extract to your project directory

Option 2: Using Command Line

mkdir my-spring-app
cd my-spring-app

Create pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>myapp</name>
    <description>Spring Boot App for Out Plane</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Create the directory structure:

mkdir -p src/main/java/com/example/myapp
mkdir -p src/main/resources

Create Application Code

Create src/main/java/com/example/myapp/MyappApplication.java:

package com.example.myapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyappApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyappApplication.class, args);
    }
}

Create src/main/java/com/example/myapp/HomeController.java:

package com.example.myapp;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
public class HomeController {

    @GetMapping("/")
    public Map<String, String> home() {
        return Map.of("message", "Hello from Out Plane");
    }

    @GetMapping("/health")
    public Map<String, String> health() {
        return Map.of("status", "healthy");
    }
}

Configure for Production

Create src/main/resources/application.properties:

# Server configuration
server.port=${PORT:8080}

# Actuator endpoints for health checks
management.endpoints.web.exposure.include=health,info
management.endpoint.health.show-details=always

This configuration reads the port from the PORT environment variable, defaulting to 8080.

Create the Dockerfile

Create a file called Dockerfile in your project root:

FROM eclipse-temurin:17-jdk-alpine AS builder

WORKDIR /app

COPY pom.xml .
COPY .mvn .mvn
COPY mvnw .

RUN chmod +x mvnw
RUN ./mvnw dependency:go-offline -B

COPY src ./src

RUN ./mvnw package -DskipTests -B

FROM eclipse-temurin:17-jre-alpine

WORKDIR /app

COPY --from=builder /app/target/*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "app.jar"]

If you don't have the Maven wrapper (mvnw), generate it with: mvn wrapper:wrapper

Create a .dockerignore file:

target
.git
.gitignore
*.md
.idea
*.iml
.DS_Store

Test Locally

Build and run the application:

./mvnw spring-boot:run

Or build the JAR and run it:

./mvnw package -DskipTests
java -jar target/myapp-0.0.1-SNAPSHOT.jar

Open http://localhost:8080 in your browser. You should see the JSON response.

Test the health endpoint at http://localhost:8080/health.

Push to GitHub

Initialize a Git repository and push to GitHub:

git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:YOUR_USERNAME/my-spring-app.git
git branch -M main
git push -u origin main

Replace YOUR_USERNAME with your GitHub username.

Deploy on Out Plane

Step 1: Install GitHub App

  1. Go to console.outplane.com
  2. Navigate to Applications from the sidebar
  3. Click Deploy Application
  4. If prompted, click Install GitHub App
  5. Select which repositories Out Plane can access
  6. Click Install and you'll be redirected back

Step 2: Select Repository

  1. Find your repository in the list
  2. Click to select it
  3. Choose the branch to deploy (default: main)
  4. Set Root Directory to /

Step 3: Configure Build

SettingValue
Build MethodSelect Dockerfile
Application NameEnter a unique name (e.g., my-spring-app)
Port8080

Step 4: Select Resources

InstancevCPURAMRecommended For
op-4611 GBSmall apps
op-8222 GBProduction (recommended)
op-9444 GBHigh traffic

Spring Boot applications typically require at least 512MB RAM. For production workloads, op-82 or higher is recommended.

Step 5: Configure Scaling

  • Min Scale: Set to 1 for always-on, or 0 for scale-to-zero
  • Max Scale: Set based on expected traffic

Step 6: Environment Variables (Optional)

Click Add Variable to add environment variables:

KeyValue
SPRING_PROFILES_ACTIVEproduction
DATABASE_URLYour database connection string

Step 7: Deploy

  1. Review your configuration
  2. Click Create Application
  3. Wait for the build to complete (typically 3-5 minutes)

Step 8: Access Your App

Once the deployment status shows Ready:

  1. Go to the application Overview tab
  2. Find your domain: my-spring-app.outplane.app
  3. Click to open your live application
  4. Check health at my-spring-app.outplane.app/actuator/health

Adding a Database

Step 1: Create a Database

  1. Go to Databases in the sidebar
  2. Click Create Database
  3. Choose a name, PostgreSQL version, and region
  4. Click Create Database

Step 2: Get Connection String

  1. Click on your database
  2. In the Overview tab, find the connection details
  3. Note the host, port, database name, username, and password

Step 3: Add PostgreSQL Dependency

Add to your pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

Step 4: Configure Database Connection

Update src/main/resources/application.properties:

# Server configuration
server.port=${PORT:8080}

# Database configuration
spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/mydb}
spring.datasource.username=${DATABASE_USERNAME:postgres}
spring.datasource.password=${DATABASE_PASSWORD:}

# JPA configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

Step 5: Add Environment Variables

  1. Go to your application in Out Plane
  2. Click SettingsEnvironment
  3. Add the database variables:
KeyValue
DATABASE_URLjdbc:postgresql://host:5432/dbname
DATABASE_USERNAMEYour database username
DATABASE_PASSWORDYour database password
  1. Click Save and redeploy

Production Optimizations

JVM Memory Settings

For production, optimize JVM memory in your Dockerfile:

ENTRYPOINT ["java", "-XX:+UseContainerSupport", "-XX:MaxRAMPercentage=75.0", "-jar", "app.jar"]

Using Gradle Instead

If you prefer Gradle, create build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '17'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

Update your Dockerfile for Gradle:

FROM eclipse-temurin:17-jdk-alpine AS builder
WORKDIR /app
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
RUN chmod +x gradlew
RUN ./gradlew dependencies --no-daemon
COPY src src
RUN ./gradlew bootJar --no-daemon

FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY --from=builder /app/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

Automatic Deployments

Push to your branch to trigger automatic deployments:

git add .
git commit -m "Add new feature"
git push origin main

Next Steps

Buildpack alternative: Instead of Dockerfile, select Buildpack. Spring Boot apps are auto-detected and built using the Paketo buildpack.