Assembling via Spring's Java Config
Explore how to use Spring's Java Config to assemble web applications with modular configuration classes. Understand how to manage beans, apply annotations like @Configuration and @Bean, and create flexible, testable application contexts that isolate modules such as persistence adapters.
We'll cover the following...
Java Config
While classpath scanning is the cudgel of application assembly, Spring’s Java Config is the scalpel. 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.
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:
The @Configuration annotation
The @Configuration annotation marks this class as a configuration class to be picked
up by Spring’s classpath scanning. So, in this case, we’re still using classpath ...