“Time to show off your Spring Boot prowess—let’s launch your very own “Hello, World” API into the wild via Heroku!” 🚀🐒

🏁 Challenge: Build & Deploy Your Hello API

Follow these steps and get your service live in under 10 minutes.


1️⃣ Bootstrap Your Project

Use Spring Initializr (or your IDE):

  • Dependencies: Spring Web
  • Group: com.example
  • Artifact: hello-app

Open the generated project in your IDE.


2️⃣ Add the Hello Controller

Create src/main/java/com/example/helloapp/HelloController.java:

javaCopyEditpackage com.example.helloapp;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        return "🐵 Hello, Heroku!";
    }
}

3️⃣ Verify Locally

bashCopyEdit./mvnw clean package
./mvnw spring-boot:run

Visit http://localhost:8080/hello to see your greeting.


4️⃣ Prepare for Heroku

  1. Initialize Git bashCopyEditgit init git add . git commit -m "Initial Spring Boot Hello API"
  2. Create Procfile at project root: bashCopyEditweb: java -jar target/hello-app-0.0.1-SNAPSHOT.jar
  3. Add system.properties (to pin Java version): iniCopyEditjava.runtime.version=17

5️⃣ Deploy!

  1. Login & Create App bashCopyEditheroku login heroku create your-unique-app-name
  2. Push to Heroku bashCopyEditgit push heroku main
  3. Scale Dynos (ensure at least one web dyno): bashCopyEditheroku ps:scale web=1
  4. Open in Browser bashCopyEditheroku open or visit https://your-unique-app-name.herokuapp.com/hello

6️⃣ Verify & Celebrate

You should see 🐵 Hello, Heroku! live on the internet. 🎉


🤔 Bonus Tips

  • Custom Domain: heroku domains:add www.yourdomain.com
  • Environment Variables: heroku config:set SPRING_PROFILES_ACTIVE=prod
  • Logging: heroku logs --tail to debug in real time.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *