JohnathanMarkSmith/HelloSpringJavaBasedJavaConfig — pull request #2 by joshlong (2013-04-26 17:51:17+00:00)
Title: i saw your tweet

Hi i saw your tweet so i update the code a little. let me know if that helps. basically, you just had some string that wouldn't work in the @ComponentScan. I removed it and instead chose to use package based scanning in the AnnotationConfigApplicationContext instead. If you use @ComponentScan, prefer typed classes, like this:

@ComponentScan(basePackageClasses = { SomeComponentInMyPackages.class })

that way your code is refactor-friendly and there are no magic strings in your code. Spring will simply scan all the components in - or below - the package in which the specified class lives.

Alternatively, in Spring 3.2+, put your configuration at the lowest possible package, and simply use @ComponentScan (without no attributes) and it will scan everything in or below the package in which the @Configuration class is situated.

a.b.c.ApplicationConfiguration // with @ComponentScan
a.b.c.services.SomeService // with @Service
a.b.c.controllers.SomeSpringMvcControllers // with @Controller