One of the problems with Spring before annotations was the size of the application context XML files. Application context XML files ran into hundreds of lines (sometimes, even thousands of lines). However, with annotations, there is no need for such long application context XML files anymore.
We recommend that you use component scans to locate and autowire the beans instead of manually wiring the beans in XML files. Keep your application context XML files very small. We recommend that you use Java @Configuration
wherever some framework-related configuration is needed.
When using component scan, we recommend that you use the basePackageClasses
attribute. The following snippet shows an example:
@ComponentScan(basePackageClasses = ApplicationController.class) public class SomeApplication {
The basePackageClasses
attribute is the type-safe alternative to basePackages()
in order to specify the...