Chapter 3. Advanced wiring

 

This chapter covers

  • Spring profiles
  • Conditional bean declaration
  • Autowiring and ambiguity
  • Bean scoping
  • The Spring Expression Language

In the previous chapter, we looked at some essential bean-wiring techniques. You’re likely to find a lot of use for what you learned in that chapter. But there’s more to bean wiring than what we explored in chapter 2. Spring has several other tricks up its sleeve for more advanced bean wiring.

In this chapter, we’ll dig in to some of these advanced techniques. You won’t get as much day-to-day use out of the techniques in this chapter, but that doesn’t mean they’re any less valuable.

3.1. Environments and profiles

One of the most challenging things about developing software is transitioning an application from one environment to another. Certain environment-specific choices made for development aren’t appropriate or won’t work when the application transitions from development to production. Database configuration, encryption algorithms, and integration with external systems are just a few examples of things that are likely to vary across deployment environments.

Consider database configuration, for instance. In a development environment, you’re likely to use an embedded database preloaded with test data. For example, in a Spring configuration class, you might use EmbeddedDatabaseBuilder in an @Bean method like this:

3.2. Conditional beans

3.3. Addressing ambiguity in autowiring

3.4. Scoping beans

3.5. Runtime value injection

3.6. Summary

sitemap