More Constructors

  • Spring will automatically construct your @RestController classes...
  • But it will also construct your other classes too!
@RestController
class CalculatorController {
    private final MyCalculator calculator;
    public CalculatorController(MyCalculator calculator) {
        this.calculator = calculator;
    }

    @GetMapping("/add/{a}/{b}")
    public double add(double a, double b) {
        return this.calculator.add(a,b);
    }
}

29 / 31