Skip to content

Java / Spring Boot Hello World

Create a Spring Boot application with a REST controller.

src/main/java/com/example/demo/HelloController.java:

package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
public class HelloController {
@GetMapping("/")
public Map<String, String> hello() {
return Map.of("message", "Hello World");
}
}

src/main/java/com/example/demo/DemoApplication.java:

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

Run it locally:

Terminal window
./mvnw spring-boot:run
Terminal window
curl http://localhost:8080
# {"message":"Hello World"}

Ready to deploy? Use the Origin Clouds CLI or SDK to push your app.

Deploy to Origin Clouds →