Labs ICT
Pro Login

Deployment Options

Deploying to cloud platforms and servers.

Deployment Options

Your Spring Boot app is ready to face the real world. Now you need to decide where to put it. The good news is Spring Boot gives you options — cloud platforms, containers, or traditional servers. Pick what fits your needs and budget.

Cloud platforms like Heroku and AWS are popular because they handle infrastructure for you. Docker gives you consistency across environments. Traditional servers give you full control. Each has its place.

Deploying to Heroku

Heroku is the easiest way to get your app online. Push your code to a Git repository, and Heroku detects it's a Spring Boot app. It builds and deploys automatically. You can have your app running in minutes, not hours.

The free tier is perfect for small projects and learning. Heroku handles SSL, load balancing, and scaling. You just focus on your code.

heroku create my-spring-app
git push heroku main
heroku logs --tail

Deploying to AWS

AWS gives you more control and options. You can use Elastic Beanstalk for easy deployment, ECS for container orchestration, or EC2 for full server control. It's more complex than Heroku, but more powerful.

For most Spring Boot apps, Elastic Beanstalk is the sweet spot. Upload your JAR, and AWS handles the rest. You can scale up or down with a few clicks.

eb init -p java-11 my-app
eb create my-app-env
eb deploy
eb open

Docker Deployment

Docker containers package your app with everything it needs to run. Write a Dockerfile, build an image, and deploy anywhere that supports Docker. Your app runs the same on your laptop as it does in production.

Docker Compose makes it easy to run your app with databases and other services. It's perfect for development and testing environments.

FROM eclipse-temurin:17-jre-alpine
VOLUME /tmp
COPY target/myapp-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]

docker build -t myapp .
docker run -p 8080:8080 myapp

Traditional Server Deployment

Sometimes you need to deploy to an existing server. Maybe your company has a Tomcat setup, or you're using a virtual private server. Spring Boot supports this too — just build a WAR file instead of a JAR.

Switch your packaging to war in pom.xml and extend SpringBootServletInitializer. Your app can now run on external Tomcat, Jetty, or any other servlet container.

<packaging>war</packaging>

public class MyApp extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MyApp.class);
    }
}

java -jar myapp-0.0.1-SNAPSHOT.war