Deploy Spring Boot on DCDeploy
This guide helps you deploy a Spring Boot application on DCDeploy—from setup, build config, to monitoring.Quick Start: Hello World
You can deploy a minimal Spring Boot app to test the flow.-
Create a new Spring Boot project (using Spring Initializr or CLI):
- Modify src/main/java/com/example/demo/DemoApplication.java:
- Add a Dockerfile (if using Docker for deployment) or prepare the build to be invoked by DCDeploy.
- Push the code to a Git repository.
- Deploy on DCDeploy using the steps in this guide.
Overview
Spring Boot is a Java framework for building production-grade standalone applications with embedded servers (Tomcat, Jetty, etc.). On DCDeploy, you can deploy Spring Boot apps via:- Build from Code (auto-detecting Java/Maven/Gradle projects)
- Dockerfile, for full control (custom JVM options, multi-stage builds)
Prerequisites
- Java 17+ or appropriate version for your app.
- Build tool: Maven or Gradle in your repo.
- pom.xml or build.gradle describing dependencies.
- A Git repository.
- If using Docker, include a Dockerfile.
- Application should read port from environment (e.g. $ or fallback) and listen on 0.0.0.0.
Step-by-Step Guide
- Prepare Your Spring Boot App
- Ensure your main class (with @SpringBootApplication) is correctly set.
- Update application.properties or application.yml to use environment variables:
- Add Dockerfile (optional but often preferred) Example Dockerfile with multi-stage build:
- Push Code to Git
- Initialize Git if needed, commit all files.
- If using .gitignore, exclude target/, .mvn/, .settings, etc.
- Deploy on DCDeploy
- In DCDeploy dashboard → go to your environment → Deploy tab.
- Add a new service → choose Build from Code or Docker Registry.
- Provide repo + branch.
- Set port to 8080 (or configured port), ensure the app listens on 0.0.0.0.
- Choose protocol (HTTP/HTTPS), region(s).
- Provide environment variables:
- DATABASE_URL, DB_USER, DB_PASS etc.
- SPRING_PROFILES_ACTIVE if you use profiles.
- Choose machine type (CPU/RAM) based on expected load.
- Set scaling parameters (minScale / maxScale).
- Deploy and monitor build & deployment logs.
Example Service Configuration
Best Practices
- Use multi-stage Docker builds to reduce image size.
- Set server.port dynamically via $ environment variable.
- Use internal networking for databases and other services inside DCDeploy.
- Use health checks (for example /actuator/health) to allow DCDeploy to monitor readiness.
- Configure logging and monitoring.
- Use secrets instead of hard-coded credentials.
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| App not reachable | Application not listening on 0.0.0.0 or wrong port | Verify server.port property and listening address. |
| Build failed (Maven or Gradle errors) | Missing dependencies, repository issues | Ensure your build file is correct, test build locally. |
| Environment variables missing or wrong | Variables not set in DCDeploy service/profile | Set up env vars in service manifest or dashboard. |
| Long cold start or high memory usage | Large jar size, many dependencies | Use slim base image, strip dependencies, optimize build. |
| Database connection errors | Wrong JDBC URL, DB not reachable | Check DATABASE_URL, internal network, DNS, and private network usage. |
