Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Advanced Java Enterprise & Concurrency 24 mins read Free Lesson

Spring Boot REST Architecture & Dependency Injection

Scaffold enterprise Spring Boot microservices with @RestController, @Service, @Repository, and Spring Data JPA.

Spring Boot Production REST Controller

package com.etutorial.api;

import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import java.util.List;

@RestController
@RequestMapping("/api/v1/tutorials")
public class TutorialController {
    private final TutorialService service;

    public TutorialController(TutorialService service) {
        this.service = service;
    }

    @GetMapping
    public ResponseEntity<List<TutorialDto>> getAllFreeTutorials() {
        return ResponseEntity.ok(service.findAllFree());
    }
}