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...