The bean of the DataServiceImpl class needs to be injected into that of the BusinessServiceImpl class.
We can do that by specifying an @Autowired annotation in the instance variable of the DataService interface in the BusinessServiceImpl class:
@Service
public class BusinessServiceImpl {
@Autowired
private DataService dataService;
Now that we have defined the beans and their wiring, to test this, we need an implementation of DataService. We will create a simple, hardcoded implementation. DataServiceImpl returns a couple of pieces of data:
@Repository
public class DataServiceImpl implements DataService {
public List<Data> retrieveData(User user) {
return Arrays.asList(new Data(10), new Data(20));
}
}
Now that we have our beans and dependencies defined, let's focus on how to create and run a Spring IoC container.