There is another type- safe alternative to locating the base package as String. Check out the API here , but I also illustrated below:
@ComponentScan(basePackageClasses = {ExampleController.class, ExampleModel.class, ExmapleView.class})
Using the basePackageClasses specifier with your class references, tell Spring to scan these packages (just like the alternatives mentioned), but this method is safe in type and adds IDE support for future refactoring - a huge plus in my book.
Reading from the API, Spring suggests creating a no-op marker class or interface in every package that you want to scan, which serves no other purpose than to use as a reference for / using this attribute.
IMO, I donβt like marker classes (but again, they are pretty much like packet-information classes), but type safety, IDE support and a significant reduction in the number of basic packages that need to be enabled for this scan are, without a doubt, much better option.
Prancer Jan 24 '14 at 12:55 2014-01-24 12:55
source share