# Spring Boot

A Spring Boot 3.5 REST API starter in Java 17, built with the Maven wrapper, for Java developers who want a clean Spring Web service to rename and extend. It includes a controller, a service and record DTOs, Bean Validation, RFC 9457 error responses and JUnit 5 tests with MockMvc.

- Framework: Spring Boot (Java)
- Category: Starters / REST APIs
- Creates: a server app
- Plan: Free
- Price: Free
- Author: Light Cloud
- Page: https://templates.light-cloud.com/starters/rest-apis/spring-boot-api-starter
- Updated: 2026-11-21

## Features

- GET / returns a welcome message and GET /hello?name=Ada returns {"message": "Hello, Ada!"}
- name defaults to World and must be 1 to 50 characters, otherwise the API answers 400
- A global exception handler answers every error as application/problem+json, including 404 for unknown routes
- Unexpected exceptions are logged and answered with a generic 500 problem, so stack traces stay on the server
- Package-by-feature layout: HelloController, HelloService and the MessageResponse record side by side in hello/
- JUnit 5 tests: a @SpringBootTest context check and @WebMvcTest MockMvc tests, including the 400 problem
- server.port reads PORT with 8080 as the fallback
- Maven wrapper included, so ./mvnw spring-boot:run works without installing Maven

## What you need

- Free plan: it runs as a server app, and the Free plan includes 3 server apps
- To run it locally: a JDK for Java 17 or newer (the Maven wrapper downloads Maven)
- No API keys: it starts with nothing to configure

## About

The starter uses plain Spring Web on embedded Tomcat with constructor injection, records for responses and a @RestControllerAdvice that extends ResponseEntityExceptionHandler, so Spring's own errors and yours share one format. The hello package is the pattern to copy: add a sibling package with its own controller, service and records, and component scanning picks it up. Light Cloud builds the jar with Maven and runs it as a container on PORT, redeploying on each push to your copy.

## Questions

### How do I add a new REST endpoint in Spring Boot?

Create a package next to hello/ with a @RestController class and a @GetMapping or @PostMapping method that returns a record. Component scanning finds it, so there is nothing to register.

### How do I return RFC 9457 problem details in Spring Boot?

This starter already does: GlobalExceptionHandler extends ResponseEntityExceptionHandler, so validation errors and unknown routes come back as application/problem+json. Return a ProblemDetail from your own @ExceptionHandler methods to add more cases.

### How do I add Swagger UI to a Spring Boot API?

Add the org.springdoc:springdoc-openapi-starter-webmvc-ui dependency to pom.xml. springdoc then serves Swagger UI at /swagger-ui.html.

### How do I connect this Spring Boot starter to PostgreSQL?

Add spring-boot-starter-data-jpa and the PostgreSQL driver to pom.xml and set the spring.datasource properties from environment variables. The spring-boot-postgresql-crud-api template has this already wired up.

### Can I run this Spring Boot app without Light Cloud?

Yes. Build it with ./mvnw clean package and run java -jar target/*.jar on any host with Java 17, or build a container image with ./mvnw spring-boot:build-image.
