Assembling via Spring’s Java Config
While classpath scanning is the cudgel of application assembly, Spring’s Java Config is the scalpel.2 This approach is similar to the plain code approach introduced earlier in this chapter, but it’s less messy and provides us with a framework so that we don’t have to code everything by hand.
2 Cudgel versus scalpel: if you don’t spend far too many hours of your life killing monsters in role-playing video games like me and don’t know what a cudgel is, a cudgel is a stick with a weighted end that can be used as a weapon. It’s a very blunt weapon that can do a lot of damage without having to aim particularly well.
In this approach, we create configuration classes, each responsible for constructing a set of beans that are to be added to the application context.
For example, we could create a configuration class that is responsible for instantiating all our persistence adapters: