I am beginner at Spring / Spring Boot and I have a look at some Spring / Spring Boot projects and realized that, in some of them DI is applied using constructor as shown below:
@RestController
@RequestMapping("/api/v1/core")
public class DemoController {
private final SalaryService salaryService;
private final EmployeeService employeeService;
public DemoController(SalaryService salaryService, EmployeeService employeeService) {
this.salaryService = salaryService;
this.employeeService = employeeService;
}
}
However, in some projects, DI is applied via annotations and the code is simplified. Is it possible to use annotations in Spring or Spring Boot and simplify the code by removing constructor? And if so, is that applied to Service, Repository and Controller?