Performance assessment with different configurations

In this section, we will learn how different types of bean configuration impact application performance, and also we will see the best practices of bean configuration.

Let's see how the @ComponentScan annotation configuration impacts the startup time of a Spring application:

@ComponentScan (( {{ "org", "com" }} ))

As per the preceding configuration, Spring will scan all the packages of com and org and, because of that, the startup time of the application will be increased. So, we should scan only those packages that have annotated classes, as non-annotated classes will take time to scan. We should use only one @ComponentScan and list all packages, as shown here:

@ComponentScan(basePackages={"com.packt.springhighperformance.ch2.bankingapp.model","com.packt.springhighperformance.ch2.bankingapp.service"})

The preceding configuration is considered as a best practice of defining the @ComponentScan annotation. We should specify which of those packages as basePackage attribute have annotated classes. It will reduce the startup time of the application.

..................Content has been hidden....................

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