For production code, it's prudent to declare dependencies explicitly rather than using autowire, so that there are fewer moving parts in the production setup.
This is similar to good practice of using only fully qualified import statements instead of import my.super.project.dao.*
(Autowiring by the way is a very useful feature for integration tests)
So to hook things up in production, a good way to go is just plain old constructor dependency injection into final fields. Using final fields where possible minimizes mutability.
Service class, which receives the daos through injection:
public class CompanyService implements ICompanyService {
private final EmployeeDao employeeDao;
private final DepartmentDao departmentDao;
public CompanyService(EmployeeDao employeeDao, DepartmentDao departmentDao) {
this.employeeDao = employeeDao;
this.departmentDao = departmentDao;
}
...
}
And then the controller receives the service through injection (using the interface type):
@Controller
public class MyController
{
private final ICompanyService companyService;
public MyController(ICompanyService companyService) {
this.companyService = companyService;
}
@RequestMapping("/data")
public @RequestBody Data getData(@RequestParam String id)
{
return companyService.queryForData(id);
}
}