A quick review

Let's take a moment and review all the things we have done until now to get this example working:

  • We have defined a Spring configuration class SpringContext with the @Configuration annotation with a component scan for the com.mastering.spring package
  • We have a couple of files (in the preceding package):
    • BusinessServiceImpl with the @Service annotation
    • DataServiceImpl with the @Repository annotation
  • BusinessServiceImpl has the @Autowired annotation on the instance of DataService

When we launch up a Spring context, the following things will happen:

  • It will scan the com.mastering.spring package and find the BusinessServiceImpl and DataServiceImpl beans.
  • DataServiceImpl does not have any dependency. So, the bean for DataServiceImpl is created.
  • BusinessServiceImpl has a dependency on DataService. DataServiceImpl is an implementation of the DataService interface. So, it matches the autowiring criteria. So, a bean for BusinessServiceImpl is created and the bean created for DataServiceImpl is autowired to it through the setter.
..................Content has been hidden....................

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