The constructor injection

The constructor injection, on the other hand, uses a constructor to inject dependencies. The following code shows you how to use a constructor for injecting in DataService:

    public class BusinessServiceImpl { 
private DataService dataService;
@Autowired
public BusinessServiceImpl(DataService dataService) {
super();
this.dataService = dataService;
}
}

When you run the code with the preceding implementation of BusinessServiceImpl, you will see this statement in the log, asserting that autowiring took place using the constructor:

    Autowiring by type from bean name 'businessServiceImpl' via 
constructor to bean named 'dataServiceImpl'
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset